Instant Diffs

Instant Diffs is a JavaScript tool that enhances MediaWiki diff links with interactive functionality — dynamically loaded content via AJAX technology in dialog windows.

目前為 2025-08-02 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Instant Diffs
// @namespace    https://www.mediawiki.org/wiki/Instant_Diffs
// @version      1.1.1
// @description  Instant Diffs is a JavaScript tool that enhances MediaWiki diff links with interactive functionality — dynamically loaded content via AJAX technology in dialog windows.
// @author       Serhio Magpie
// @license      MIT
// @match        https://*/*
// @icon         https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Instant_Diffs_logo.svg/64px-Instant_Diffs_logo.svg.png
// @grant        GM_setValue
// @grant        GM_getValue
// @run-at       document-start
// ==/UserScript==

/* jshint esversion: 8 */

( ( window ) => {
    'use strict';

    /**
     * Semantic Versioning Comparing
     * @see {@link https://gist.github.com/iwill/a83038623ba4fef6abb9efca87ae9ccb}
     * @see {@link https://semver.org/}
     * @see {@link https://stackoverflow.com/a/65687141/456536}
     * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options}
     */
    function semverCompare( a, b ) {
        if ( a.startsWith( b + '-' ) ) return -1;
        if ( b.startsWith( a + '-' ) ) return 1;
        return a.localeCompare( b, undefined, { numeric: true, sensitivity: 'case', caseFirst: 'upper' } );
    }

    window.RLQ = window.RLQ || [];
    window.RLQ.push( () => {
        if ( typeof window.mw === 'undefined' ) return;

        window.mw.loader.enqueue( [ 'mediawiki.base' ], () => {
            const minimumVersion = '1.35';
            const currentVersion = window.mw.config.get( 'wgVersion' );
            if ( semverCompare( currentVersion, minimumVersion ) < 0 ) {
                console.error( `Instant Diffs: requires MediaWiki ${ minimumVersion }+, got ${ currentVersion }.` );
                return;
            }

            window.instantDiffs = window.instantDiffs || {};
            window.instantDiffs.GM = GM;

            window.mw.loader.getScript( 'https://www.mediawiki.org/w/index.php?title=User:Serhio_Magpie/instantDiffs.js&instantdiffs[GM]=true&action=raw&ctype=text/javascript' )
                .then( () => {
                    console.info( `Instant Diffs: loaded successfully.` );
                }, ( error ) => {
                    console.error( `Instant Diffs: loading failed: ${ error.message }.` );
                } );
        } );
    } );
} ) ( window.unsafeWindow );