plsDirectJump

This is a script (planned) to remove cushion pages such as 2ch.net and FC2 Wiki from <a href> so that you can jump directly to them.

目前为 2022-02-01 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name plsDirectJump
  3. // @namespace https://github.com/PC-CNT/UserscriptWorks/
  4. // @version 0.2.8
  5. // @description This is a script (planned) to remove cushion pages such as 2ch.net and FC2 Wiki from <a href> so that you can jump directly to them.
  6. // @description:ja <a href>から2ch.netやFC2 Wikiなどのクッションページを削除して直接飛ぶようにするスクリプト(の予定)です。
  7. // @author PC-CNT
  8. // @license MIT
  9. // @supportURL https://github.com/PC-CNT/UserscriptWorks/issues
  10. // @include *://*
  11. // @include https://www.youtube.com/watch?v=*
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15.  
  16. ( () => {
  17. "use strict";
  18.  
  19. console.log("===START UserscriptWorks/plsDirectJump===");
  20.  
  21. const flag_debug = false;
  22.  
  23. function http_https(host) {
  24. if (host.match("https")) {
  25. return "https";
  26. } else {
  27. return "http";
  28. }
  29. }
  30.  
  31. function fixPrefix(url) {
  32. if (url.match(/^https?:\/\//)) {
  33. return url;
  34. } else {
  35. return "//" + url;
  36. }
  37. }
  38.  
  39. function isURL(text) {
  40. if (text.match(/^https?:\/\//) && !(text.match(/^[0-9]{1,2}:[0-9]{2}/))) {
  41. return true;
  42. } else {
  43. return false;
  44. }
  45. }
  46.  
  47. //* 配列の先頭をタイトルとしたconsole.groupの表示
  48. function debug(msglist) {
  49. if (!flag_debug) {
  50. return;
  51. }
  52. console.group(msglist[0]);
  53. msglist.slice(1).forEach(msg => {
  54. console.info(msg);
  55. });
  56. console.groupEnd();
  57. }
  58.  
  59.  
  60. function youtube() {
  61. //* YouTube(米欄)
  62. //* (https://www.youtube.com/watch?v=1X2TwPb3y10)
  63. //! 以下メモ
  64. //* #comments -> #sections -> #contents:米全体 -> ytd-comment-thread-renderer:米一つずつ
  65. //* -> #comment -> #body -> #main -> #expander -> #content -> #content-text -> spanまたはa
  66. //* class="style-scope ytd-comment-renderer"
  67. //* "yt-confirm-dialog-renderer" 警告のダイアログ (desktop_polymer.jsに書いてあるけど全然わからん)
  68. //* .yt-simple-endpoint このクラスがついてるとダイアログでる
  69. //! ここまでメモ
  70.  
  71. const target = document.getElementById("content")
  72. const config = {childList: true, subtree: true}
  73.  
  74. const observer = new MutationObserver(() => {
  75. const content_text = document.querySelectorAll("#content-text");
  76. if ((content_text) && (content_text.length)) {
  77. content_text.forEach(block => {
  78. // console.info(block);
  79. block.querySelectorAll("a").forEach(function(value) {
  80. let a_text = value.innerText;
  81. if (isURL(a_text)) {
  82. console.info("value:", value);
  83. let _youtube = ["match:Youtube"];
  84. _youtube.push("絶対パス:" + a_text);
  85. value.classList.remove("yt-simple-endpoint");
  86. value.style.textDecoration = "none";
  87. value.setAttribute("href", a_text);
  88. value.setAttribute("target", "_blank");
  89. value.setAttribute("rel", "noopener noreferrer");
  90. debug(_youtube);
  91. }
  92. });
  93. });
  94. }
  95. });
  96. observer.observe(target, config);
  97. }
  98.  
  99. function others() {
  100. document.querySelectorAll("a").forEach(function(value) {
  101. let url_source_abs = value.href;
  102. let url_source_rel = value.getAttribute("href")
  103. //TODO: hrefの編集
  104. if (url_source_abs) {
  105. if (url_source_abs.match(/^https?:\/\/jump.(2|5)ch\.net\/\?.*/)) {
  106. //* 2ちゃんねる
  107. //* (jump.5ch.net/?http://example.com/example.html, jump.2ch.net/?,)
  108. let _2ch = ["match:2ch.net", "絶対パス:" + url_source_abs];
  109. value.setAttribute("href", fixPrefix(url_source_abs.replace(/^https?:\/\/jump.(2|5)ch\.net\/\?/, "")));
  110. _2ch.push("変更後パス:" + value.href);
  111. debug(_2ch);
  112. }
  113. // if (url_source_abs.match(/^https?:\/\/.+\.wiki\.fc2\.com\/jump\//)) {
  114. if (location.hostname.match(/^.+\.wiki\.fc2\.com/)) {
  115. //* FC2 Wiki
  116. //* (https://example.wiki.fc2.com/jump/https/example.com%2exapmple)
  117. let _fc2 = ["match:FC2 Wiki", "絶対パス:" + url_source_abs, "相対パス:" + url_source_rel];
  118. if (url_source_rel.match(/^\/jump\/https?\/.*/)) {
  119. value.setAttribute("href", decodeURIComponent(url_source_rel.replace(/^\/jump\/https?\//, http_https(url_source_abs) + "://")));
  120. value.setAttribute("target", "_blank");
  121. value.setAttribute("rel", "noopener noreferrer");
  122. _fc2.push("変更後パス:" + value.href);
  123. debug(_fc2);
  124. }
  125. }
  126. if (url_source_abs.match(/^https?:\/\/kakaku\.com\/jump\/\?url=.*/)) {
  127. //* 価格.com
  128. //* (https://kakaku.com/jump/?url=https%3A%2F%2Fwww%2Eexample%2Ecom%2F)
  129. let _kakaku = ["match:価格.com", "絶対パス:" + url_source_abs];
  130. value.setAttribute("href", decodeURIComponent(url_source_abs.replace(/^https?:\/\/kakaku\.com\/jump\/\?url=/, "")));
  131. _kakaku.push("変更後パス:" + value.href);
  132. debug(_kakaku);
  133. }
  134. }
  135. });
  136. }
  137.  
  138. if (location.host.match(/^www\.+youtube\.com/)) {
  139. youtube();
  140. } else {
  141. others();
  142. }
  143.  
  144. console.log("===END UserscriptWorks/plsDirectJump===");
  145. })();