GC - Quickstock Gallery Shortener

replace long gallery names with shorter ones. I FOUND THIS ON GOOGLE I DID NOT MAKE IT LOL, i just edited a little for gc

  1. // ==UserScript==
  2. // @name GC - Quickstock Gallery Shortener
  3. // @copyright JoeSimmons
  4. // @description replace long gallery names with shorter ones. I FOUND THIS ON GOOGLE I DID NOT MAKE IT LOL, i just edited a little for gc
  5. // @match https://www.grundos.cafe/quickstock/
  6. // @version 1.1.0
  7. // @namespace https://greasyfork.org/users/748951
  8. // ==/UserScript==
  9.  
  10. (function () {
  11. 'use strict';
  12.  
  13.  
  14.  
  15.  
  16. var words = {
  17. ///////////////////////////////////////////////////////
  18.  
  19.  
  20. // Syntax: 'Full Gallery Name' : 'Short Name/Emoji',
  21. 'felt emo, might delete' : '🖤',
  22. 'Usuki Dreamhouse' : '🎎',
  23. 'Pretty in Pink' : '🌸',
  24. 'Keepsakes' : '🎁🍃',
  25.  
  26.  
  27. ///////////////////////////////////////////////////////
  28. '':''};
  29.  
  30. /*
  31. NOTE ABOUT SPECIAL CHARACTERS:
  32. You can use \\* to match actual asterisks instead of using it as a wildcard!
  33. The examples below show a wildcard in use and a regular asterisk replacement.
  34.  
  35. // Syntax: 'Search word' : 'Replace word',
  36. 'your a' : 'you\'re a',
  37. 'imo' : 'in my opinion',
  38. 'im\\*o' : 'matching an asterisk, not a wildcard',
  39. '/\\bD\\b/g' : '[D]',
  40. */
  41.  
  42.  
  43.  
  44.  
  45.  
  46. //////////////////////////////////////////////////////////////////////////////
  47. // This is where the real code is
  48. // Don't edit below this
  49. //////////////////////////////////////////////////////////////////////////////
  50.  
  51. var regexs = [], replacements = [],
  52. tagsWhitelist = ['PRE', 'BLOCKQUOTE', 'CODE', 'INPUT', 'BUTTON', 'TEXTAREA'],
  53. rIsRegexp = /^\/(.+)\/([gim]+)?$/,
  54. word, text, texts, i, userRegexp;
  55.  
  56. // prepareRegex by JoeSimmons
  57. // used to take a string and ready it for use in new RegExp()
  58. function prepareRegex(string) {
  59. return string.replace(/([\[\]\^\&\$\.\(\)\?\/\\\+\{\}\|])/g, '\\$1');
  60. }
  61.  
  62. // function to decide whether a parent tag will have its text replaced or not
  63. function isTagOk(tag) {
  64. return tagsWhitelist.indexOf(tag) === -1;
  65. }
  66.  
  67. delete words['']; // so the user can add each entry ending with a comma,
  68. // I put an extra empty key/value pair in the object.
  69. // so we need to remove it before continuing
  70.  
  71. // convert the 'words' JSON object to an Array
  72. for (word in words) {
  73. if ( typeof word === 'string' && words.hasOwnProperty(word) ) {
  74. userRegexp = word.match(rIsRegexp);
  75.  
  76. // add the search/needle/query
  77. if (userRegexp) {
  78. regexs.push(
  79. new RegExp(userRegexp[1], 'g')
  80. );
  81. } else {
  82. regexs.push(
  83. new RegExp(prepareRegex(word).replace(/\\?\*/g, function (fullMatch) {
  84. return fullMatch === '\\*' ? '*' : '[^ ]*';
  85. }), 'g')
  86. );
  87. }
  88.  
  89. // add the replacement
  90. replacements.push( words[word] );
  91. }
  92. }
  93.  
  94. // do the replacement
  95. texts = document.evaluate('//body//text()[ normalize-space(.) != "" ]', document, null, 6, null);
  96. for (i = 0; text = texts.snapshotItem(i); i += 1) {
  97. if ( isTagOk(text.parentNode.tagName) ) {
  98. regexs.forEach(function (value, index) {
  99. text.data = text.data.replace( value, replacements[index] );
  100. });
  101. }
  102. }
  103.  
  104. }());