GitHub: remove canonical

remove Github's canonical link

目前为 2014-05-18 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @id GitHub: remove canonical
  3. // @name GitHub: remove canonical
  4. // @namespace http://efcl.info
  5. // @description remove Github's canonical link
  6. // @include https://github.com/*/*
  7. // @version 0.0.1.20140518104254
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. //const currentPath = unsafeWindow.GitHub.currentPath;// 現在地
  12. const repoName = unsafeWindow.GitHub.repoName;// レポジトリかどうか確認に使う
  13. const controllerName = unsafeWindow.GitHub.controllerName;// tree , commmit
  14. const currentRef = unsafeWindow.GitHub.currentRef;// master - Canonicalはmasterの時の変更されてるかな?
  15. if (!repoName) {
  16. return; // レポジトリじゃない
  17. }
  18. main();
  19. function checkCanonical(href) {
  20. // 状況をtreeに限定して、masterにいる時(原因のGithub)はcanonicalを書き換える。
  21. // 今は困った仕様でlocation.pathname !== href の状況なので、一致になったらこの子はいらない
  22. if (controllerName === "tree" && currentRef === "master"
  23. && location.pathname === href) {
  24. alert("Githubは何か変更したよ\n私はもういらない子かも");
  25. }
  26. }
  27.  
  28. function getCanonical() {
  29. var link = document.querySelector('link[rel="canonical"]');
  30. if (link) {
  31. return link;
  32. }
  33. }
  34.  
  35. function main() {
  36. var link = getCanonical();
  37. if (!link) {
  38. return;
  39. }
  40. // checkCanonical(link.href);// Githubが変更してくれるといいね
  41. link.parentNode.removeChild(link);
  42. }
  43. })();