resource.AddWorkshop Generator

Extract item IDs and names for Garry's Mod to help quickly create a resource.AddWorkshop lua file.

当前为 2024-01-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name resource.AddWorkshop Generator
  3. // @version 1.0
  4. // @description Extract item IDs and names for Garry's Mod to help quickly create a resource.AddWorkshop lua file.
  5. // @author Eggroll & ChatGPT
  6. // @match https://steamcommunity.com/sharedfiles/filedetails/?id=*
  7. // @grant none
  8. // @namespace https://gf.qytechs.cn/users/1248228
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Check if the subscribeCollection element is present
  15. var subscribeCollection = document.querySelector('.subscribeCollection');
  16. if (subscribeCollection) {
  17. // Your code here
  18. var mods = Array.from(document.querySelectorAll('[id^="sharedfile_"]')).map(mod => {
  19. var modId = mod.id.replace('sharedfile_', '');
  20. var modName = mod.querySelector('.workshopItemTitle').textContent;
  21. return { id: modId, name: modName };
  22. });
  23.  
  24. var luaOutput = mods.map(mod => `resource.AddWorkshop( "${mod.id}" ) -- ${mod.name}`).join('\n');
  25.  
  26. // Create a button
  27. var button = document.createElement('button');
  28. button.textContent = 'Copy GLua List';
  29.  
  30. // Copy styles from the general_btn subscribe button
  31. var referenceButton = document.querySelector('.general_btn.subscribe');
  32. if (referenceButton) {
  33. var computedStyles = window.getComputedStyle(referenceButton);
  34. for (var i = 0; i < computedStyles.length; i++) {
  35. button.style[computedStyles[i]] = computedStyles.getPropertyValue(computedStyles[i]);
  36. }
  37. }
  38.  
  39. // Explicitly set white-space property to nowrap
  40. button.style.whiteSpace = 'nowrap';
  41.  
  42. // Set text-align to center
  43. button.style.textAlign = 'center';
  44.  
  45. // Attach the button to the subscribeCollection element
  46. subscribeCollection.appendChild(button);
  47.  
  48. // Add hover styles
  49. button.addEventListener('mouseover', function() {
  50. button.style.backgroundColor = '#97C0E3';
  51. button.style.setProperty('-webkit-text-fill-color', '#3C3D3E', 'important');
  52. });
  53.  
  54. // Set padding to 0 on both x and y axes
  55. button.style.padding = '0';
  56.  
  57. button.style.width = '126px';
  58.  
  59. // Add mouseout styles
  60. button.addEventListener('mouseout', function() {
  61. button.style.backgroundColor = '#0e1720'; // Revert to default
  62. button.style.setProperty('-webkit-text-fill-color', '#939393', 'important');
  63. });
  64.  
  65. // Add a click event listener to the button
  66. button.addEventListener('click', function() {
  67. // Print the lua code in console as a fallback in case this fails for some reason
  68. console.log(`${luaOutput}`);
  69. // Copy luaOutput to clipboard
  70. navigator.clipboard.writeText(luaOutput).then(function() {
  71. // Change button text after copying
  72. button.textContent = 'Copied!';
  73. // Reset button text after 2 seconds
  74. setTimeout(function() {
  75. button.textContent = 'Copy Glua List';
  76. }, 2000);
  77. }).catch(function(err) {
  78. console.error('Unable to copy text to clipboard!!!', err);
  79. });
  80. });
  81. }
  82. })();

QingJ © 2025

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