GitHub: remove canonical

remove Github's canonical link

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
    }
})();