User:HenryLi/vector-2022.js

出自維基百科,自由嘅百科全書
注意:儲存之後,你可能要兜過你嘅瀏覽器快取至睇到更改。Internet Explorer: 撳住Ctrl掣再撳重新整理掣。 Firefox: 撳住Shift掣再撳重新載入(又或者撳Ctrl-Shift-R)。 Google Chrome同埋Safari用戶就噉撳個重載掣。
$(function () {
    const thumbInners = document.querySelectorAll('.thumbinner')
    const imgs = document.querySelectorAll('img:not([class])')
    const thumbImgs = document.querySelectorAll('img.thumbimage')
    const infoboxes = document.querySelectorAll('table.infobox')

    const ths = document.querySelectorAll('th')
    thumbInners.forEach(
        function(thumbInner, currentIndex, listObj) {
            var thumbImage = thumbInner.querySelector('.thumbimage')
            var height = thumbImage.getAttribute('height')
            var fileWidth = thumbImage.getAttribute('data-file-width')
            var fileHeight = thumbImage.getAttribute('data-file-height')
            var calcWidth = 250 * fileWidth / fileHeight

            thumbInner.style.removeProperty('width')
            //thumbInner.style.setProperty('height', height + 'px')
            thumbInner.style.setProperty('height', '250px')
            thumbInner.style.setProperty('max-height', '250px')

            thumbImage.style.setProperty('width', calcWidth + 'px')
            thumbImage.style.setProperty('height', '250px')

        },
        'argument'
    )
    imgs.forEach(
        function(img, currentIndex, listObj) {

            var height = img.getAttribute('height')
            var width = img.getAttribute('width')
            var fileWidth = img.getAttribute('data-file-width')
            var fileHeight = img.getAttribute('data-file-height')
            var calcWidth = 250 * fileWidth / fileHeight
            img.style.setProperty('max-height', '250px')

            if (width == 300) {
              img.style.setProperty('height', '250px')

              img.style.setProperty('width', calcWidth + 'px')

            }

        },
        'argument'
    )
    infoboxes.forEach(
        function(infobox, currentIndex, listObj) {
            infobox.style.removeProperty('width')
            infobox.style.setProperty('height', '30%')
            infobox.style.setProperty('max-height', '22em')
        },
        'argument'
    )

    ths.forEach(
        function(th, currentIndex, listObj) {
             var width = th.style['width']

             if (width) {

                 th.style.removeProperty('width')
                 th.style.setProperty('height', width)
             }
        },
        'argument'
    )

}());