GreasyFork Sites Show for Users (GFSSU)

Show @match and @include URLs for scripts on user pages on GreasyFork with a toggle feature

  1. // ==UserScript==
  2. // @name GreasyFork Sites Show for Users (GFSSU)
  3. // @namespace https://your-namespace-here
  4. // @version 1.0
  5. // @description Show @match and @include URLs for scripts on user pages on GreasyFork with a toggle feature
  6. // @author Emree.el on instagram
  7. // @match https://greasyfork.org/en/users/*
  8. // @grant GM_xmlhttpRequest
  9. // @require https://code.jquery.com/jquery-3.6.0.min.js
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Process each script list item
  17. $('li[data-script-id]').each(function() {
  18. let scriptElement = $(this);
  19. let codeUrl = scriptElement.attr('data-code-url');
  20.  
  21. if (codeUrl) {
  22. // Fetch the script content
  23. GM_xmlhttpRequest({
  24. method: "GET",
  25. url: codeUrl,
  26. onload: function(response) {
  27. if (response.status === 200) {
  28. // Extract @match and @include lines
  29. let matchUrls = response.responseText.match(/\/\/\s*@match\s+(\S+)/g) || [];
  30. let includeUrls = response.responseText.match(/\/\/\s*@include\s+(\S+)/g) || [];
  31. let allUrls = matchUrls.concat(includeUrls);
  32.  
  33. if (allUrls.length > 0) {
  34. let matchList = $('<ul class="url-list" style="list-style-type: disc; margin-left: 20px;"></ul>');
  35. allUrls.forEach(function(line, index) {
  36. let url = line.replace(/\/\/\s*@(match|include)\s+/, '').trim();
  37. let listItem = $(`<li style="display: ${index >= 3 ? 'none' : 'list-item'};">${url}</li>`);
  38. matchList.append(listItem);
  39. });
  40.  
  41. let toggleButton = null;
  42. if (allUrls.length > 3) {
  43. toggleButton = $('<button style="margin-left: 10px; cursor: pointer; background: #ddd; border: none; padding: 2px 5px;">+</button>');
  44.  
  45. toggleButton.click(function() {
  46. let isExpanded = $(this).text() === '-';
  47. $(this).text(isExpanded ? '+' : '-');
  48. matchList.children('li').slice(3).toggle(!isExpanded);
  49. });
  50. }
  51.  
  52. // Append the @match and @include URLs under the script description
  53. scriptElement.find('h2').after(matchList);
  54.  
  55. // Add the toggle button next to the script title link
  56. if (toggleButton) {
  57. scriptElement.find('a.script-link').after(toggleButton);
  58. }
  59. }
  60. }
  61. }
  62. });
  63. }
  64. });
  65. })();