Open Elements in Background Tab

將選定的元素在背景分頁或新分頁開啟

  1. // ==UserScript==
  2. // @name Open Elements in Background Tab
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.8
  5. // @description 將選定的元素在背景分頁或新分頁開啟
  6. // @author You
  7. // @match https://tixcraft.com/ticket/area/*
  8. // @grant GM_openInTab
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // 從頁面腳本中提取 areaUrlList
  18. function extractAreaUrlList() {
  19. const scripts = document.getElementsByTagName('script');
  20. let urlList = {};
  21.  
  22. for (const script of scripts) {
  23. if (script.textContent.includes('var areaUrlList =')) {
  24. try {
  25. const match = script.textContent.match(/var areaUrlList = (\{[^;]+\});/);
  26. if (match && match[1]) {
  27. urlList = JSON.parse(match[1]);
  28. console.log('Successfully extracted areaUrlList:', urlList);
  29. }
  30. } catch (e) {
  31. console.error('Error parsing areaUrlList:', e);
  32. }
  33. }
  34. }
  35. return urlList;
  36. }
  37.  
  38. // 開啟所有連結
  39. function openAllUrls(urlList) {
  40. const urls = Object.values(urlList);
  41. console.log(`Opening ${urls.length} tabs...`);
  42.  
  43. // 為了避免被瀏覽器阻擋,添加小延遲
  44. urls.forEach((url, index) => {
  45. setTimeout(() => {
  46. GM_openInTab(url, { active: false });
  47.  
  48. // 在最後一個 URL 開啟後輸出完成訊息
  49. if (index === urls.length - 1) {
  50. console.log('All tabs have been opened!');
  51. }
  52. }, index * 100); // 每個標籤頁延遲 100ms
  53. });
  54. }
  55.  
  56. function init() {
  57. const urlList = extractAreaUrlList();
  58.  
  59. // 檢查是否有區域可以開啟
  60. if (Object.keys(urlList).length > 0) {
  61. console.log('Found areas, opening tabs...');
  62. // 自動開啟所有連結
  63. openAllUrls(urlList);
  64. } else {
  65. console.log('No areas found to open');
  66. }
  67. }
  68.  
  69. // 等待一小段時間確保頁面完全載入
  70. setTimeout(() => {
  71. if (document.readyState === 'complete') {
  72. init();
  73. } else {
  74. window.addEventListener('load', init);
  75. }
  76. }, 100); // 等待 500ms 再執行
  77. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址