Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Ylis UID-Hide
- // @version 1.0
- // @match http://ylilauta.org/*
- // @match https://ylilauta.org/*
- // @grant none
- // ==/UserScript==
- $(document).ready(function() {
- $.fn.extend({
- insertAtCaret: function(startTag, endTag, e) {
- if (typeof endTag == 'undefined')
- endTag = '';
- if (typeof e == 'undefined')
- e = '';
- return this.each(function() {
- if (document.selection) {
- sel = document.selection.createRange();
- sel.text = startTag + sel.text + endTag;
- if (!e.metaKey && !e.ctrlKey) {
- this.focus();
- }
- } else if (this.selectionStart || this.selectionStart == '0') {
- selectedText = this.value.substr(this.selectionStart, (this.selectionEnd - this.selectionStart));
- startPos = this.selectionStart;
- endPos = this.selectionEnd;
- this.value = this.value.substring(0, startPos) + startTag + selectedText + endTag + this.value.substring(endPos, this.value.length);
- if (!e.metaKey && !e.ctrlKey) {
- this.focus();
- }
- if (selectedText.length == 0) {
- this.selectionStart = startPos + startTag.length;
- this.selectionEnd = startPos + startTag.length;
- } else {
- this.selectionStart = this.value.length;
- this.selectionEnd = this.value.length;
- }
- } else {
- this.value += startTag + endTag;
- if (!e.metaKey && !e.ctrlKey) {
- this.focus();
- }
- }
- });
- }
- });
- function setStorage(sname, val) {
- localStorage.setItem(sname, val);
- }
- function getStorage(sname) {
- return localStorage.getItem(sname);
- }
- var allscripts = ['hidepostsbyid'];
- function checkStorage(reset) {
- if (reset === 'reset') {
- setStorage('firstrun', '1');
- Object.keys(localStorage).forEach(function(key) {
- if (/hiddenUIDs$/.test(key)) {
- localStorage.removeItem(key);
- }
- });
- }
- }
- checkStorage();
- if (/preferences/.test(location.pathname)) {
- $('#site').append('<span class="block"><input type="checkbox" class="scriptoption" id="hidepostsbyid" name="hidepostsbyid"> <label for="hidepostsbyid">Ctrl+Click UID-Hide</label></span>');
- }
- $('.scriptoption').each(function() {
- var optname = $(this).attr('id');
- var optvalue = getStorage(optname);
- if (optvalue !== '0') {
- $(this).prop('checked', true);
- } else {
- $(this).prop('checked', false);
- }
- });
- $('.scriptoption').change(function() {
- var optname = $(this).attr('id');
- var optvalue = getStorage(optname);
- if (optvalue !== '0') {
- setStorage(optname, '0');
- } else {
- setStorage(optname, '1');
- }
- });
- if (getStorage('hidepostsbyid') !== '0' || undefined) {
- var hideUID = function(threadID, UID) {
- if( getStorage(threadID + 'hiddenUIDs') === null || undefined) {
- setStorage(threadID + 'hiddenUIDs', UID);
- } else {
- var hiddenUIDs = getStorage(threadID + 'hiddenUIDs');
- var newHiddenUIDs = hiddenUIDs + ' ' + UID;
- setStorage(threadID + 'hiddenUIDs', newHiddenUIDs);
- }
- };
- $('.answer .postinfo .postuid').click(function(e) {
- if(e.ctrlKey) {
- var threadID = $(this).closest('.thread').attr('id').substr(7);
- var UID = $(this).text().substr(4);
- hideUID(threadID, UID);
- $(this).closest('.answer').hide();
- $('.answer .postinfo .postuid').each(function() {
- var threadID = $(this).closest('.thread').attr('id').substr(7);
- var UID = new RegExp($(this).text().substr(4));
- var hiddenUIDs = getStorage(threadID + 'hiddenUIDs');
- if (UID.test(hiddenUIDs)) {
- $(this).closest('.answer').hide();
- }
- });
- }
- });
- $('.answer .postinfo .postuid').each(function() {
- var threadID = $(this).closest('.thread').attr('id').substr(7);
- var UID = new RegExp($(this).text().substr(4));
- var hiddenUIDs = getStorage(threadID + 'hiddenUIDs');
- if (UID.test(hiddenUIDs)) {
- $(this).closest('.answer').hide();
- }
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement