Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Ylis UID-Hide
  3. // @version 1.0
  4. // @match http://ylilauta.org/*
  5. // @match https://ylilauta.org/*
  6. // @grant none
  7. // ==/UserScript==
  8.  
  9.  
  10. $(document).ready(function() {
  11.  
  12. $.fn.extend({
  13. insertAtCaret: function(startTag, endTag, e) {
  14. if (typeof endTag == 'undefined')
  15. endTag = '';
  16. if (typeof e == 'undefined')
  17. e = '';
  18. return this.each(function() {
  19. if (document.selection) {
  20. sel = document.selection.createRange();
  21. sel.text = startTag + sel.text + endTag;
  22. if (!e.metaKey && !e.ctrlKey) {
  23. this.focus();
  24. }
  25. } else if (this.selectionStart || this.selectionStart == '0') {
  26. selectedText = this.value.substr(this.selectionStart, (this.selectionEnd - this.selectionStart));
  27. startPos = this.selectionStart;
  28. endPos = this.selectionEnd;
  29. this.value = this.value.substring(0, startPos) + startTag + selectedText + endTag + this.value.substring(endPos, this.value.length);
  30. if (!e.metaKey && !e.ctrlKey) {
  31. this.focus();
  32. }
  33. if (selectedText.length == 0) {
  34. this.selectionStart = startPos + startTag.length;
  35. this.selectionEnd = startPos + startTag.length;
  36. } else {
  37. this.selectionStart = this.value.length;
  38. this.selectionEnd = this.value.length;
  39. }
  40. } else {
  41. this.value += startTag + endTag;
  42. if (!e.metaKey && !e.ctrlKey) {
  43. this.focus();
  44. }
  45. }
  46. });
  47. }
  48. });
  49.  
  50. function setStorage(sname, val) {
  51. localStorage.setItem(sname, val);
  52. }
  53.  
  54. function getStorage(sname) {
  55. return localStorage.getItem(sname);
  56. }
  57.  
  58. var allscripts = ['hidepostsbyid'];
  59.  
  60. function checkStorage(reset) {
  61.  
  62. if (reset === 'reset') {
  63. setStorage('firstrun', '1');
  64.  
  65. Object.keys(localStorage).forEach(function(key) {
  66. if (/hiddenUIDs$/.test(key)) {
  67. localStorage.removeItem(key);
  68. }
  69. });
  70. }
  71. }
  72.  
  73. checkStorage();
  74.  
  75. if (/preferences/.test(location.pathname)) {
  76.  
  77. $('#site').append('<span class="block"><input type="checkbox" class="scriptoption" id="hidepostsbyid" name="hidepostsbyid"> <label for="hidepostsbyid">Ctrl+Click UID-Hide</label></span>');
  78.  
  79.  
  80. }
  81.  
  82. $('.scriptoption').each(function() {
  83. var optname = $(this).attr('id');
  84. var optvalue = getStorage(optname);
  85. if (optvalue !== '0') {
  86. $(this).prop('checked', true);
  87. } else {
  88. $(this).prop('checked', false);
  89. }
  90. });
  91.  
  92. $('.scriptoption').change(function() {
  93. var optname = $(this).attr('id');
  94. var optvalue = getStorage(optname);
  95. if (optvalue !== '0') {
  96. setStorage(optname, '0');
  97. } else {
  98. setStorage(optname, '1');
  99. }
  100. });
  101.  
  102. if (getStorage('hidepostsbyid') !== '0' || undefined) {
  103.  
  104. var hideUID = function(threadID, UID) {
  105. if( getStorage(threadID + 'hiddenUIDs') === null || undefined) {
  106. setStorage(threadID + 'hiddenUIDs', UID);
  107. } else {
  108. var hiddenUIDs = getStorage(threadID + 'hiddenUIDs');
  109. var newHiddenUIDs = hiddenUIDs + ' ' + UID;
  110. setStorage(threadID + 'hiddenUIDs', newHiddenUIDs);
  111. }
  112. };
  113.  
  114. $('.answer .postinfo .postuid').click(function(e) {
  115. if(e.ctrlKey) {
  116. var threadID = $(this).closest('.thread').attr('id').substr(7);
  117. var UID = $(this).text().substr(4);
  118. hideUID(threadID, UID);
  119. $(this).closest('.answer').hide();
  120.  
  121. $('.answer .postinfo .postuid').each(function() {
  122. var threadID = $(this).closest('.thread').attr('id').substr(7);
  123. var UID = new RegExp($(this).text().substr(4));
  124. var hiddenUIDs = getStorage(threadID + 'hiddenUIDs');
  125.  
  126. if (UID.test(hiddenUIDs)) {
  127. $(this).closest('.answer').hide();
  128. }
  129.  
  130. });
  131.  
  132. }
  133. });
  134.  
  135. $('.answer .postinfo .postuid').each(function() {
  136. var threadID = $(this).closest('.thread').attr('id').substr(7);
  137. var UID = new RegExp($(this).text().substr(4));
  138. var hiddenUIDs = getStorage(threadID + 'hiddenUIDs');
  139.  
  140. if (UID.test(hiddenUIDs)) {
  141. $(this).closest('.answer').hide();
  142. }
  143. });
  144.  
  145. }
  146.  
  147. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement