Greasy Fork Install Button at search

adds install button at search and at user pages.

  1. // ==UserScript==
  2. // @name Greasy Fork Install Button at search
  3. // @namespace -
  4. // @version 1.0.0
  5. // @description adds install button at search and at user pages.
  6. // @author NotYou
  7. // @match *://*sleazyfork.org/*
  8. // @match *://*greasyfork.org/*
  9. // @grant none
  10. // @run-at document-idle
  11. // @license GPL-3.0-or-later
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. var $ = (s) => document.querySelector(s)
  16.  
  17. var $$ = (s) => document.querySelectorAll(s)
  18.  
  19. var appendHTML = function(el, html) {
  20. el.insertAdjacentHTML('beforeend', html)
  21. }
  22.  
  23. var domain = location.host
  24.  
  25. // STYLES
  26. appendHTML($('head'), ['<style>',
  27.  
  28. '.custom-install-link-parent {',
  29. 'text-decoration: none !important;',
  30. '}',
  31.  
  32. '.custom-install-link-parent > * {',
  33. 'transform: scale(0.7);',
  34. '}',
  35.  
  36. '.custom-install-link {',
  37. 'margin-right: -15px !important;',
  38. 'margin-left: -6px !important;',
  39. '}',
  40.  
  41. '.custom-install-style-link {',
  42. 'margin-left: -14px !important;',
  43. 'margin-right: -26px !important;',
  44. '}',
  45.  
  46. '</style>'].join(''))
  47.  
  48. // USER SCRIPT
  49.  
  50. $$('#user-script-list > li[data-script-type="public"] > article > h2 > a, #browse-script-list > li[data-script-type="public"] > article > h2 > a').forEach(function(e) {
  51. var data = e.parentNode.parentNode.parentNode.dataset
  52. var scriptId = data.scriptId
  53. var scriptName = data.scriptName
  54.  
  55. appendHTML(e, '<span data-install-format="js" data-script-id="'+ scriptId +'" data-script-name="' + scriptName + '"><a href="https://' + domain + '/scripts/' + scriptId + '/code/' + scriptName + '.user.js" class="custom-install-link-parent"><span class="install-link custom-install-link">Install</span></a><span>')
  56. })
  57.  
  58. // USER STYLE
  59.  
  60. $$('#user-script-list > li[data-script-language="css"] > article > h2 > a, #browse-script-list > li[data-script-language="css"] > article > h2 > a').forEach(function(e) {
  61. var data = e.parentNode.parentNode.parentNode.dataset
  62. var scriptId = data.scriptId
  63. var scriptName = data.scriptName
  64.  
  65. appendHTML(e, '<span data-install-format="css" data-script-id="'+ scriptId +'" data-script-name="' + scriptName + '"><a target="_blank" href="https://' + domain + '/scripts/' + scriptId + '/code/' + scriptName + '.user.css" class="custom-install-link-parent"><span class="install-link custom-install-link custom-install-style-link">Install as style</span></a><span>')
  66. })
  67.  
  68. // LIBRARIES
  69.  
  70. $$('#user-library-script-list > li > article > h2 > a, #browse-script-list > li[data-script-type="library"] > article > h2 > a').forEach(function(e) {
  71. var data = e.parentNode.parentNode.parentNode.dataset
  72. var scriptId = data.scriptId
  73. var scriptName = data.scriptName
  74. var _scriptName = scriptName.replace(/\s/g, "-")
  75.  
  76. appendHTML(e, '<span data-install-format="js" data-script-id="'+ scriptId +'" data-script-name="' + scriptName + '"><a href=javascript:void(0) onclick=navigator.clipboard.writeText("https://' + domain + '/scripts/' + scriptId + '/code/' + _scriptName + '.js") class="custom-install-link-parent"><span class="install-link custom-install-link">Copy URL</span></a><span>')
  77. })
  78. })()
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.