skip open external link alert

for gamer site

  1. // ==UserScript==
  2. // @name skip open external link alert
  3. // @description for gamer site
  4. // @namespace ref_redir
  5. // @author Covenant
  6. // @version 1.0
  7. // @license MIT
  8. // @homepage
  9. // @match https://ref.gamer.com.tw/redir.php?url=*
  10. // @match https://www.gamer.com.tw/*
  11. // @match https://forum.gamer.com.tw/*
  12. // @match https://home.gamer.com.tw/*
  13. // @match https://webcache.googleusercontent.com/search?q=cache:https://forum.gamer.com.tw/*
  14. // @match https://webcache.googleusercontent.com/search?q=cache:https://home.gamer.com.tw/*
  15. // @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>
  16. // @grant GM_setValue
  17. // @grant GM_getValue
  18. // @grant GM_registerMenuCommand
  19. // @run-at document-end
  20. // @noframes
  21. // ==/UserScript==
  22. var baha_ref_redir=GM_getValue('baha_ref_redir', 3000);
  23. var baha_ref_redir_replace=GM_getValue('baha_ref_redir_replace', false);
  24. function fn_url(url){
  25. let obj_url=new URL(url);
  26. let params=obj_url.searchParams;
  27. //let params=new URLSearchParams(obj_url.search);
  28. return [obj_url,params];
  29. }
  30. //console.log("break");
  31. function main_01() {
  32. var txt=document.querySelectorAll('div>p');
  33. for(let i = 0; i < txt.length; i++){
  34. if(txt[i].style.color=='blue'&&(txt[i].innerText.search(new RegExp("Https://", "i"))==0||txt[i].innerText.search(new RegExp("Http://", "i"))==0)){
  35. window.location.replace(txt[i].innerText);
  36. }
  37. }
  38. }
  39. (function() {
  40. 'use strict';
  41. let url=fn_url(document.location);
  42. 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){
  43. GM_registerMenuCommand("0秒跳轉⚡", () => {
  44. GM_setValue('baha_ref_redir',1);
  45. });
  46. GM_registerMenuCommand("3秒跳轉🔔", () => {
  47. GM_setValue('baha_ref_redir',3000);
  48. });
  49. GM_registerMenuCommand("5秒跳轉⏳", () => {
  50. GM_setValue('baha_ref_redir',5000);
  51. });
  52. console.log(baha_ref_redir);
  53. window.onload = function(){
  54. var timeoutID = window.setInterval(( () => main_01() ), baha_ref_redir);//延遲3秒
  55. };
  56. }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){
  57. if(baha_ref_redir_replace){
  58. GM_registerMenuCommand("還原提醒不明連結", () => {
  59. GM_setValue('baha_ref_redir_replace',!baha_ref_redir_replace);
  60. });
  61. }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){
  62. GM_registerMenuCommand("啟用移除redir.php(beta)", () => {
  63. GM_setValue('baha_ref_redir_replace',!baha_ref_redir_replace);
  64. });
  65. }
  66. if(baha_ref_redir_replace){
  67. let anchor=document.querySelectorAll('a');
  68. for(let i = 0; i < anchor.length; i++){
  69. if(anchor[i].href.search(new RegExp("https://ref.gamer.com.tw/redir.php\\?url=", "i"))==0){
  70. anchor[i].href=decodeURIComponent(anchor[i].href).replace(/https:\/\/ref.gamer.com.tw\/redir\.php\?url=/i, '');
  71. anchor[i].title="redir";
  72. }
  73. }
  74. }
  75. }
  76. })();