巴哈姆特 - 自動跳轉外鏈

RT

目前為 2023-11-20 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name skip open external link alert
  3. // @name:zh-TW 巴哈姆特 - 自動跳轉外鏈
  4. // @description for gamer site
  5. // @description:zh-tw RT
  6. // @namespace ref_redir
  7. // @author Covenant
  8. // @version 1.0
  9. // @license MIT
  10. // @homepage
  11. // @match https://ref.gamer.com.tw/redir.php?url=*
  12. // @match https://www.gamer.com.tw/*
  13. // @match https://forum.gamer.com.tw/*
  14. // @match https://home.gamer.com.tw/*
  15. // @match https://webcache.googleusercontent.com/search?q=cache:https://forum.gamer.com.tw/*
  16. // @match https://webcache.googleusercontent.com/search?q=cache:https://home.gamer.com.tw/*
  17. // @icon data:image/svg+xml,<svg width="26" height="23" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M10.434 1.462.402 18.612C-.74 20.563.687 23 2.966 23h20.068c2.28 0 3.706-2.437 2.564-4.387L15.566 1.463c-1.142-1.95-3.99-1.95-5.132 0z" fill="%239B9B9B"/><path d="M13.995 17.357c.253.25.395.566.395.956s-.143.725-.395.975c-.289.25-.609.37-1.004.37s-.719-.14-.968-.39c-.288-.25-.41-.565-.41-.955s.126-.71.41-.956c.253-.25.573-.37.968-.37s.735.125 1.004.37zm.181-9.64-.383 7.679a.673.673 0 0 1-.675.635h-.238c-.36 0-.66-.28-.675-.635l-.383-7.679a.671.671 0 0 1 .675-.702h1c.387 0 .695.32.675.702h.004z" fill="%23fff"/></svg>
  18. // @grant GM_setValue
  19. // @grant GM_getValue
  20. // @grant GM_registerMenuCommand
  21. // @run-at document-end
  22. // @noframes
  23. // ==/UserScript==
  24. var baha_ref_redir=GM_getValue('baha_ref_redir', 3000);
  25. var baha_ref_redir_replace=GM_getValue('baha_ref_redir_replace', false);
  26. function fn_url(url){
  27. let obj_url=new URL(url);
  28. let params=obj_url.searchParams;
  29. //let params=new URLSearchParams(obj_url.search);
  30. return [obj_url,params];
  31. }
  32. //console.log("break");
  33. function main_01() {
  34. var txt=document.querySelectorAll('div>p');
  35. for(let i = 0; i < txt.length; i++){
  36. if(txt[i].style.color=='blue'&&(txt[i].innerText.search(new RegExp("Https://", "i"))==0||txt[i].innerText.search(new RegExp("Http://", "i"))==0)){
  37. window.location.replace(txt[i].innerText);
  38. }
  39. }
  40. }
  41. (function() {
  42. 'use strict';
  43. let url=fn_url(document.location);
  44. if(url[0].host.search(new RegExp("ref.gamer.com.tw", "i"))==0||url[0].host.search(new RegExp("www.gamer.com.tw", "i"))==0){
  45. GM_registerMenuCommand("0秒跳轉⚡", () => {
  46. GM_setValue('baha_ref_redir',1);
  47. });
  48. GM_registerMenuCommand("3秒跳轉🔔", () => {
  49. GM_setValue('baha_ref_redir',3000);
  50. });
  51. GM_registerMenuCommand("5秒跳轉⏳", () => {
  52. GM_setValue('baha_ref_redir',5000);
  53. });
  54. console.log(baha_ref_redir);
  55. window.onload = function(){
  56. var timeoutID = window.setInterval(( () => main_01() ), baha_ref_redir);//延遲3秒
  57. };
  58. }else if(url[0].host.search(new RegExp("forum.gamer.com.tw", "i"))==0||url[0].host.search(new RegExp("home.gamer.com.tw", "i"))==0||url[0].host.search(new RegExp("webcache.googleusercontent.com", "i"))==0){
  59. if(baha_ref_redir_replace){
  60. GM_registerMenuCommand("還原提醒不明連結", () => {
  61. GM_setValue('baha_ref_redir_replace',!baha_ref_redir_replace);
  62. });
  63. }else if(url[0].host.search(new RegExp("home.gamer.com.tw", "i"))==0||url[0].host.search(new RegExp("webcache.googleusercontent.com", "i"))==0){
  64. GM_registerMenuCommand("啟用移除redir.php(beta)", () => {
  65. GM_setValue('baha_ref_redir_replace',!baha_ref_redir_replace);
  66. });
  67. }
  68. if(baha_ref_redir_replace){
  69. let anchor=document.querySelectorAll('a');
  70. for(let i = 0; i < anchor.length; i++){
  71. if(anchor[i].href.search(new RegExp("https://ref.gamer.com.tw/redir.php\\?url=", "i"))==0){
  72. anchor[i].href=decodeURIComponent(anchor[i].href).replace(/https:\/\/ref.gamer.com.tw\/redir\.php\?url=/i, '');
  73. anchor[i].title="redir";
  74. }
  75. }
  76. }
  77. }
  78. })();