コンテンツにスキップ

英文维基 | 中文维基 | 日文维基 | 草榴社区

利用者:Kxx/vector.js

お知らせ: 保存した後、ブラウザのキャッシュをクリアしてページを再読み込みする必要があります。

多くの WindowsLinux のブラウザ

  • Ctrl を押しながら F5 を押す。

Mac における Safari

  • Shift を押しながら、更新ボタン をクリックする。

Mac における ChromeFirefox

  • Cmd Shift を押しながら R を押す。

詳細についてはWikipedia:キャッシュを消すをご覧ください。

(function() {
    var window = this,
        $ = window.$,
        document = window.document,
        parseFloat = window.parseFloat,
        getComputedStyle = window.getComputedStyle,
        ua = window.navigator,
        isIE = ua.userAgent.indexOf('Trident') !== -1;

    if (isIE)
        for (var q = [document.body]; q.length !== 0;) {
            var node = q.shift();
            if (node.nodeType === 3) {
                if (/\S/.test(node.data)) {
                    var rotate = document.createElement('rotate');
                    node.parentNode.replaceChild(rotate, node);
                    rotate.appendChild(node);
                }
            } else if (node.nodeType === 1) {
                var tag = node.tagName;
                if (!/^(BR|IMG|INPUT|OBJECT|SCRIPT|STYLE|TEXTAREA)$/.test(tag) && (tag !== 'SPAN' || node.className !== 'tex') && (tag !== 'A' || node.className !== 'NavToggle'))
                    for (node = node.firstChild; node; node = node.nextSibling)
                        q.push(node);
            }
        }

    var imgs = window.Array.prototype.slice.call(document.getElementsByTagName('img')),
        encodeURIComponent = window.encodeURIComponent,
        parseInt = window.parseInt,
        XMLHttpRequest = window.XMLHttpRequest,
        round = window.Math.round,
        setImmediate = window.setImmediate || function(func) {
        func();
    },
        xhrs = {},
        parser = new window.DOMParser(),
        serializer = new window.XMLSerializer(),
        isNaN = window.isNaN,
        isFinite = window.isFinite,
        isNumber = function(x) {
        return !isNaN(parseFloat(x)) && isFinite(x);
    },
        setSrc = function(imgs, src) {
        setImmediate(function() {
            $(imgs).each(function() {
                this.width = this.width;
                this.height = this.height;
                this.src = src;
            });
        });
    },
        div = isIE && document.createElement('div'),
        screen = window.screen,
        zoom = window.Math.max(window.devicePixelRatio, 1.75) || screen.deviceXDPI / screen.logicalXDPI || 1.75,
        isiPhone = ua.userAgent.indexOf('iPhone') !== -1;
    for (var i = 0, numImgs = imgs.length; i < numImgs; ++i) {
        var img = imgs[i], matches = /^(https?:\/\/upload\.wikimedia\.org\/.*)\/thumb(\/.*\/)(\d{14}%21|)(.*)\/(\d+)px-\4(.*)$/.exec(img.src);
        if (!matches)
            continue;
        if (matches[4].substr(-4).toLowerCase() === '.svg' && matches[6] === '.png') {
            var src = matches[1] + matches[2] + matches[3] + matches[4],
                xhr = xhrs[src];
            if (!xhr) {
                xhrs[src] = xhr = new XMLHttpRequest();
                xhr.imgs = [img];
                xhr.open('GET', src);
                xhr.onload = (function() {
                    var svg = parser.parseFromString(this.responseText, 'image/svg+xml').documentElement;
                    svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
                    if (div) {
                        var width = svg.getAttribute('width'), height = svg.getAttribute('height');
                        if (isNumber(width))
                            width += 'px';
                        if (isNumber(height))
                            height += 'px';
                        var style = div.style;
                        style.width = width;
                        style.height = height;
                        style = getComputedStyle(div);
                        var width = parseFloat(style.width), height = parseFloat(style.height);
                        svg.setAttribute('width', width);
                        svg.setAttribute('height', height);
                        if (!svg.hasAttribute('viewBox'))
                            svg.setAttribute('viewBox', '0 0 ' + width + ' ' + height);
                    }
                    setSrc(this.imgs, 'data:image/svg+xml,' + encodeURIComponent('<?xml version="1.0" encoding="UTF-8"?>\n' + serializer.serializeToString(svg)));
                }).bind(xhr);
                xhr.onerror = (function(matches) {
                    setSrc(this.imgs, matches[1] + '/thumb' + matches[2] + matches[3] + matches[4] + '/' + round(parseInt(matches[5]) * zoom) + 'px-' + matches[4] + '.png');
                }).bind(xhr, matches);
                xhr.send();
            } else
                xhr.imgs.push(img);
            img.setAttribute('src', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABEAQAAADljNBBAAAACXZwQWcAAAABAAAAAQDHlV/tAAAAAmJLR0T//xSrMc0AAAAJcEhZcwAAAEgAAABIAEbJaz4AAAAKSURBVAgdYwABAAAFAAGKbbwgAAAAAElFTkSuQmCC');
            img.removeAttribute('srcset');
        } else if (matches[6] === '' && !isiPhone && zoom !== 1) {
            var width = parseInt(img.getAttribute('width') || matches[5]);
            img.src = matches[1] + '/thumb' + matches[2] + matches[3] + matches[4] + '/' + round(width * zoom) + 'px-' + matches[4];
            img.onerror = (function(matches) {
                this.src = matches[1] + matches[2] + matches[3] + matches[4];
            }).bind(img, matches);
            img.width = width;
            img.removeAttribute('srcset');
        }
    }
})();