GitHub: remove canonical

remove Github's canonical link

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @id             GitHub: remove canonical
// @name           GitHub: remove canonical
// @namespace      http://efcl.info
// @description    remove Github's canonical link
// @include        https://github.com/*/*
// @version 0.0.1.20140518104254
// ==/UserScript==

(function() {
    //const currentPath = unsafeWindow.GitHub.currentPath;// 現在地
    const repoName = unsafeWindow.GitHub.repoName;// レポジトリかどうか確認に使う
    const controllerName = unsafeWindow.GitHub.controllerName;// tree , commmit
    const currentRef = unsafeWindow.GitHub.currentRef;// master - Canonicalはmasterの時の変更されてるかな?
    if (!repoName) {
        return; // レポジトリじゃない
    }
    main();
    function checkCanonical(href) {
        // 状況をtreeに限定して、masterにいる時(原因のGithub)はcanonicalを書き換える。
        // 今は困った仕様でlocation.pathname !== href の状況なので、一致になったらこの子はいらない
        if (controllerName === "tree" && currentRef === "master"
                && location.pathname === href) {
            alert("Githubは何か変更したよ\n私はもういらない子かも");
        }
    }

    function getCanonical() {
        var link = document.querySelector('link[rel="canonical"]');
        if (link) {
            return link;
        }
    }

    function main() {
        var link = getCanonical();
        if (!link) {
            return;
        }
        // checkCanonical(link.href);// Githubが変更してくれるといいね
        link.parentNode.removeChild(link);
    }
})();