Unity Docs Version Switcher

adds a version dropdown, forcefully redirect to older documentation versions from google

Tính đến 05-08-2017. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Unity Docs Version Switcher
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  adds a version dropdown, forcefully redirect to older documentation versions from google
// @author       EntranceJew
// @match        https://docs.unity3d.com/*
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';

    var defaultVersion = GM_getValue("default_version", null);
    var cv = getCurrentVersion();
    var versionText = '';

    if( cv.major > 5 ){
        versionText = (cv.major + 2011) + "." + cv.minor;
    } else {
        versionText = cv.major + "." + cv.minor;
    }

    var vn = document.querySelector('.version-number');
    if( !vn ){
        vn = document.querySelector('.obsolete-version-number');
    }

    while (vn.firstChild) {
        vn.removeChild(vn.firstChild);
    }
    var dd = vn.appendChild(document.querySelector('.otherversionswrapper'));
    dd.querySelector('a').innerHTML = "Version: <b>" + versionText + "</b>";

    var changeDefault = document.createElement("a");
    changeDefault.addEventListener("click", switchListeners);
    function switchListeners(){
        var wr = (changeDefault.dataset.willRemove == "yeah");
        console.log(wr);
        if( wr ){
            delete changeDefault.dataset.willRemove;
            changeDefault.innerText = "( Set As Default )";
            GM_setValue("default_version", null);
        } else {
            changeDefault.dataset.willRemove = "yeah";
            changeDefault.innerText = "( Remove As Default )";
            GM_setValue("default_version", cv);
            defaultVersion = cv;
        }
    }

    var isDefault = (cv && defaultVersion && cv.major == defaultVersion.major && cv.minor == defaultVersion.minor);
    if( isDefault ){
        changeDefault.dataset.willRemove = "yeah";
        changeDefault.innerText = "( Remove As Default )";
    } else {
        changeDefault.innerText = "( Set As Default )";
    }
    vn.appendChild(changeDefault);

    if( window.location.href != getTargetUrlFromVersion(cv.major, cv.minor, cv.page) ){
        if( !isDefault && defaultVersion !== null && cv.page ){
            window.location.href = getTargetUrlFromVersion(defaultVersion.major, defaultVersion.minor, cv.page);
        }
    }

    populateOtherVersionsContainer();
})();