Greasy Fork is available in English.

Special User Titles API

An API for adding custom titles to certain users.

Este script no debería instalarse directamente. Es una biblioteca que utilizan otros scripts mediante la meta-directiva de inclusión // @require https://update.greatest.deepsurf.us/scripts/5856/110590/Special%20User%20Titles%20API.js

  1. // ==UserScript==
  2. // @name Special User Titles API
  3. // @author Sollace
  4. // @namespace fimfiction-sollace
  5. // @version 1.2.4
  6. // @include http://www.fimfiction.net/*
  7. // @include https://www.fimfiction.net/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. function RunScript(func, mustCall, params) {
  12. if (!document.body) {
  13. var _ready = document.onready;
  14. document.onready = function() {
  15. RunScript(func, mustCall, params);
  16. if (typeof _ready === 'function') {
  17. _ready.apply(this, arguments);
  18. }
  19. }
  20. } else {
  21. var scr = document.createElement('SCRIPT');
  22. if (mustCall) {
  23. if (params) {
  24. var pars = [];
  25. for (var i = 2; i < arguments.length; i++) {
  26. pars.push(arguments[i]);
  27. }
  28. scr.innerHTML = '(' + func.toString() + ').apply(this, ' + JSON.stringify(pars) + ');';
  29. } else {
  30. scr.innerHTML = '(' + func.toString() + ')();';
  31. }
  32. } else {
  33. scr.innerHTML = func.toString();
  34. }
  35. document.body.appendChild(scr);
  36. scr.parentNode.removeChild(scr);
  37. }
  38. };
  39. RunScript.toString = (function() {
  40. var result = function toString() {
  41. return 'function ' + this.name + '() {\n [native code]\n}';
  42. }
  43. result.toString = result;
  44. return result;
  45. })();
  46. RunScript.build = function(functionText) {
  47. return {
  48. run: function(mustCall) {
  49. if (!document.body) {
  50. var me = this;
  51. var _ready = document.onready;
  52. document.onready = function() {
  53. me.run(mustCall);
  54. if (typeof _ready === 'function') {
  55. _ready.apply(this, arguments);
  56. }
  57. }
  58. } else {
  59. var scr = document.createElement('SCRIPT');
  60. if (mustCall) {
  61. scr.innerHTML = '(' + functionText + ')();';
  62. } else {
  63. scr.innerHTML = functionText;
  64. }
  65. document.body.appendChild(scr);
  66. scr.parentNode.removeChild(scr);
  67. }
  68. }
  69. }
  70. };
  71.  
  72. (function (win) {
  73. var ver = 1.21;
  74. var startup =
  75. (typeof (SpecialTitles) === 'undefined') && (typeof (win.SpecialTitles) === 'undefined') &&
  76. (win == window || (typeof (window.SpecialTitles) === 'undefined'));
  77. var scriptBody = function(ver, startup) {
  78. function STs(load) {
  79. var _registeredTitles = load != null ? load.registeredTitles() : {};
  80.  
  81. loadIn({
  82. "FimFiction Modder": [138711, 10539, 27165],
  83. "Emote Contributor": [129122]
  84. });
  85.  
  86. function loadIn(b) {
  87. for (var i in b) {
  88. if (_registeredTitles[i] == null) {
  89. _registeredTitles[i] = b[i];
  90. } else {
  91. for (var j = 0; j < b[i].length; j++) {
  92. if ((function () {
  93. for (var k = 0; k < _registeredTitles[i].length; k++) {
  94. if (b[i][j] == _registeredTitles[i][k]) return true;
  95. }
  96. return false;
  97. })()) {
  98. _registeredTitles[i].push(b[i][j]);
  99. }
  100. }
  101. }
  102. }
  103. }
  104.  
  105. this.version = function () {
  106. return ver;
  107. };
  108. this.registeredTitles = function (v) {
  109. if (typeof v === 'string') {
  110. v = JSON.parse(v);
  111. }
  112. if (v != null) {
  113. _registeredTitles = v;
  114. }
  115. return _registeredTitles;
  116. }
  117. }
  118. STs.prototype.setUpSpecialTitles = function () {
  119. for (var i in this.registeredTitles()) {
  120. this.setSpecialTitle(this.registeredTitles()[i], i);
  121. }
  122. };
  123. STs.prototype.setSpecialTitle = function (userIds, title) {
  124. for (var i = 0; i < userIds.length; i++) {
  125. $(this.avatarSelector(userIds[i])).each(function (item) {
  126. var prev = $(this.parentNode.previousSibling);
  127. if (prev.length && !prev.hasClass('author-badge')) {
  128. $(this.parentNode).before("<div class=\"author-badge\" >" + title + "</div>");
  129. }
  130. });
  131. }
  132. };
  133. STs.prototype.avatarSelector = function(userId) {
  134. return ".author > .avatar > img[src*='" + userId + "'], .author > .avatar > img[data-src*='" + userId + "']";
  135. }
  136. STs.prototype.registerUserTitle = function (user, title) {
  137. if (typeof user != 'number') return;
  138. if (this.registeredTitles()[title] == null) {
  139. this.registeredTitles()[title] = [];
  140. }
  141. for (var i = 0; i < this.registeredTitles()[title].length; i++) {
  142. if (this.registeredTitles()[title][i] == user) return;
  143. }
  144. this.registeredTitles()[title].push(user);
  145. };
  146.  
  147. if (typeof (window.SpecialTitles) !== 'undefined') {
  148. if (window.SpecialTitles.version() < ver) {
  149. window.SpecialTitles = new STs(window.SpecialTitles);
  150. }
  151. } else {
  152. window.SpecialTitles = new STs();
  153. }
  154. if (startup) {
  155. window.SpecialTitles.setUpSpecialTitles();
  156. setTimeout(function () {
  157. try {
  158. window.SpecialTitles.setUpSpecialTitles();
  159. } catch (e) {
  160. alert('Error in ticking win.SpecialTitles.setUpSpecialTitles()\n' + e);
  161. }
  162. }, 500);
  163. }
  164. }
  165. if (win != window) {
  166. RunScript(scriptBody, true, ver, startup);
  167. window.SpecialTitles = {
  168. version: function () {
  169. return win.SpecialTitles.version();
  170. },
  171. registeredTitles: function (v) {
  172. return win.SpecialTitles.registeredTitles(JSON.stringify(v));
  173. },
  174. setSpecialTitle: function (userIds, title) {
  175. RunScript.build('function() {SpecialTitles.setSpecialTitle(' + JSON.stringify(userIds) + ',"' + title + '");}').run(true);
  176. },
  177. setUpSpecialTitles: function () {
  178. RunScript.build('function() {SpecialTitles.setUpSpecialTitles();}').run(true);
  179. },
  180. registerUserTitle: function (user, title) {
  181. RunScript.build('function(user, title) {SpecialTitles.registerUserTitle("' + user + '","' + title + '");}').run(true);
  182. }
  183. };
  184. } else {
  185. scriptBody();
  186. }
  187. })(typeof (unsafeWindow) !== 'undefined' && unsafeWindow != window ? unsafeWindow : window);