CurseForge Changelog Edit Button

Add an edit button for individual file changelogs on the legacy CurseForge website

  1. // ==UserScript==
  2. // @name CurseForge Changelog Edit Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-04-10
  5. // @description Add an edit button for individual file changelogs on the legacy CurseForge website
  6. // @author nevcairiel
  7. // @match https://legacy.curseforge.com/*/mods/*/files/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=curseforge.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // find project id
  17. var editButton = document.querySelector("a[href$='/edit']")
  18. if (!editButton)
  19. return;
  20.  
  21. var matches = editButton.href.match(/\/project\/(\d+)\/files\/\d+\/edit/);
  22. if (!matches || !matches[0])
  23. return;
  24.  
  25. var projectId = matches[1];
  26.  
  27. // find the icon asset path
  28. var iconPathMathces = document.querySelector("a.button svg.icon use").getAttribute("xlink:href").match(/(\/Content\/.+\/Skins\/CurseForge\/images\/twitch)\//);
  29. var iconPath = iconPathMathces[1];
  30.  
  31. function addEditButton(row) {
  32. var fileHref = row.querySelector("a[data-action=file-link]").href
  33. var fileId = fileHref.substring(fileHref.lastIndexOf('/') + 1)
  34. var html = `<a data-project-id="${projectId}" href="/project/${projectId}/files/${fileId}/edit" class="button button--icon-only" style="margin: 0px 2px;" data-tooltip="Edit file"><span class="button__text"><svg class="icon icon-fixed-width icon-margin" viewBox="0 0 20 20" width="18" height="18"><use xlink:href="${iconPath}/Object/Settings.svg#Object/Settings"></use></svg></span></a>`;
  35. var nodes = row.querySelectorAll("td")
  36. nodes[nodes.length - 1].querySelector("div").innerHTML += html;
  37. }
  38.  
  39. var rows = document.querySelectorAll("table.project-file-listing tbody tr");
  40. for (var i = 0, row; row = rows[i]; i++) {
  41. addEditButton(row);
  42. }
  43.  
  44. // Your code here...
  45. })();

QingJ © 2025

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