GreasyFork Script Finder

获取当前页面的主域名并打开 GreasyFork 查找脚本

  1. // ==UserScript==
  2. // @name GreasyFork Script Finder
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description 获取当前页面的主域名并打开 GreasyFork 查找脚本
  6. // @author Felix
  7. // @license AGPL-3.0
  8. // @match *://*/*
  9. // @grant GM_registerMenuCommand
  10. // @grant GM_openInTab
  11. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14. // 注册菜单命令
  15. GM_registerMenuCommand("查找该域名的GreasyFork脚本", function() {
  16. // 获取当前页面的完整域名
  17. const domain = window.location.hostname;
  18. // 使用正则表达式提取主域名
  19. const mainDomain = domain.replace(/^.*\.(?:com|org|net|gov|edu|io|co|info|me|tv)(?:\.[a-z]{2,})?$/, "$&").split('.').slice(-2).join('.');
  20. // 生成 GreasyFork 搜索链接
  21. const url = `https://greasyfork.org/zh-CN/scripts/by-site/${mainDomain}`;
  22. // 在新标签页中打开该链接
  23. GM_openInTab(url, { active: true });
  24. });
  25. })();