Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // Displayable Name of your script
- // @name SpookyX
- // Brief description
- // @description Enhances functionality of FoolFuuka boards. Devloped further for more comfortable ghost-posting on the moe archives.
- // Your name, copyright
- // @author GNH
- // @copyright 2014, GNH
- // Version Number
- // @version 20
- // @include https://*4plebs.org/*
- // @include http://*4plebs.org/*
- // @include https://archive.moe/*
- // @include http://*loveisover.me/*
- // @include https://*loveisover.me/*
- // @include http://*imcute.yt/*
- // @include https://*imcute.yt/*
- // @include http://boards.foolz.us/*
- // @include https://boards.foolz.us/*
- // @include https://*nyafuu.org/*
- // @include http://*nyafuu.org/*
- // @include https://*fgts.jp/*
- // @include http://*fgts.jp/*
- // @include https://*not4plebs.org/*
- // @include http://*not4plebs.org/*
- // @grant none
- // ==/UserScript==
- /* USER OPTIONS START */
- var imgSites = "puu.sh|i.imgur.com|data.archive.moe|i.4cdn.org|i0.kym-cdn.com|[\\S]*.deviantart.net|a.pomf.se"; // Sites to embed images from
- var imgNumMaster = 1; // Max number of images to embed
- var autoplayVids = true; // Make embedded videos play automatically (they start muted, expanding unmutes)
- var hideQROptions = true; // Make the reply options hidden by default in the quick reply
- var features = {
- "postCounter":false, // Add a post counter to the reply box
- "inlineImages":true, // Load full-size images in the thread, enable click to expand
- "hidePosts":false, // Allow user to hide posts manually
- "newPosts":true, // Reflect new posts in the tab name
- "embedImages":true, // Embed image links in thread
- "inlineReplies":true, // Click replies to expand them inline
- "postQuote":true, // Clicking the post number will insert highlighted text into the reply box
- "filter":false, // Hide undesirable posts from view
- "labelYourPosts":true // Add '(You)' to your posts and links that point to them
- };
- var filterCharThreshold = 100; // Filter posts with less than this number of characters
- var filteredStringsT0 = [ // List of Tier 0 strings to filter for. Capitalisation sensitive
- //"[\\S]*(a{4,}|b{4,}|c{4,}|d{4,}|e{4,}|f{4,}|g{4,}|h{4,}|i{4,}|j{4,}|k{4,}|l{4,}|m{4,}|n{4,}|o{4,}|p{4,}|q{4,}|r{4,}|s{4,}|t{4,}|u{4,}|v{4,}|w{4,}|x{4,}|y{4,}|z{4,})[\\S]*",
- "[\\S]*(e{4,}|E{4,}|i{4,}|I{4,}|o{4,}|O{4,}|u{4,}|U{4,})[\\S]*",
- "E(G|g)(O|o)(-kun|kun)?"
- ];
- var filteredStringsT1 = [ // List of Tier 1 strings to filter for
- "daki[\\S]*",
- "ded",
- "ayy lmao",
- "incest",
- "imoutos?",
- "moonrunes",
- "tale[\\S]*[^( of witches)]",
- "ree+[\\S]*",
- "boogeyman",
- "normies"
- ];
- var filteredStringsT2 = [ // List of Tier 2 strings to filter for
- "quest whe?n[\?]*",
- "test",
- "tsukaima"
- ];
- var filteredTrips = [ // List of tripcodes to filter for
- "!!/90sanF9F3Z"
- ];
- var filteredNames = [ // List of names to filter for
- "久保島のミズゴロウ"
- ];
- /* USER OPTIONS END */
- var newPostCount = 0;
- var DocumentTitle = document.title;
- var ignoreInline = ['v'];
- var rulesBox = $(".rules_box").html();
- if(autoplayVids){var autoplayVid = "autoplay"}else{var autoplayVid=""};
- var threadID;
- var queuedYouLabels = [];
- function ThreadUpdate(features) {
- if (features.postCounter){postCounter();}
- if (features.inlineImages){inlineImages();}
- if (features.hidePosts){hidePosts();}
- if (features.newPosts){newPosts();}
- if (features.embedImages){embedImages();}
- if (features.inlineReplies){inlineReplies();}
- if (features.postQuote){postQuote();}
- if (features.filter){filter();}
- //if (features.labelYourPosts){labelYourPosts();}
- }
- $.fn.elemText = function() {
- var text = '';
- this.each(function() {
- $(this).contents().each(function() {
- if (this.nodeType == Node.TEXT_NODE)
- text += this.textContent;
- });
- });
- return text;
- };
- var escapeRegExp;
- (function () {
- // Referring to the table here:
- // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/regexp
- // these characters should be escaped
- // \ ^ $ * + ? . ( ) | { } [ ]
- // These characters only have special meaning inside of brackets
- // they do not need to be escaped, but they MAY be escaped
- // without any adverse effects (to the best of my knowledge and casual testing)
- // : ! , =
- // my test "~!@#$%^&*(){}[]`/=?+\|-_;:'\",<.>".match(/[\#]/g)
- var specials = [
- // order matters for these
- "-"
- , "["
- , "]"
- // order doesn't matter for any of these
- , "/"
- , "{"
- , "}"
- , "("
- , ")"
- , "*"
- , "+"
- , "?"
- , "."
- , "\\"
- , "^"
- , "$"
- , "|"
- ]
- // I choose to escape every character with '\'
- // even though only some strictly require it when inside of []
- , regex = RegExp('[' + specials.join('\\') + ']', 'g')
- ;
- escapeRegExp = function (str) {
- return str.replace(regex, "\\$&");
- };
- // test escapeRegExp("/path/to/res?search=this.that")
- }());
- shortcut = {
- 'all_shortcuts':{},//All the shortcuts are stored in this array
- 'add': function(shortcut_combination,callback,opt) {
- //Provide a set of default options
- var default_options = {
- 'type':'keydown',
- 'propagate':false,
- 'disable_in_input':false,
- 'target':document,
- 'keycode':false
- };
- if(!opt) opt = default_options;
- else {
- for(var dfo in default_options) {
- if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
- }
- }
- var ele = opt.target;
- if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
- var ths = this;
- shortcut_combination = shortcut_combination.toLowerCase();
- //The function to be called at keypress
- var func = function(e) {
- e = e || window.event;
- if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields
- var element;
- if(e.target) element=e.target;
- else if(e.srcElement) element=e.srcElement;
- if(element.nodeType==3) element=element.parentNode;
- if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;
- }
- //Find Which key is pressed
- if (e.keyCode) code = e.keyCode;
- else if (e.which) code = e.which;
- var character = String.fromCharCode(code).toLowerCase();
- if(code == 188) character=","; //If the user presses , when the type is onkeydown
- if(code == 190) character="."; //If the user presses , when the type is onkeydown
- var keys = shortcut_combination.split("+");
- //Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
- var kp = 0;
- //Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
- var shift_nums = {
- "`":"~",
- "1":"!",
- "2":"@",
- "3":"#",
- "4":"$",
- "5":"%",
- "6":"^",
- "7":"&",
- "8":"*",
- "9":"(",
- "0":")",
- "-":"_",
- "=":"+",
- ";":":",
- "'":"\"",
- ",":"<",
- ".":">",
- "/":"?",
- "\\":"|"
- };
- //Special Keys - and their codes
- var special_keys = {
- 'esc':27,
- 'escape':27,
- 'tab':9,
- 'space':32,
- 'return':13,
- 'enter':13,
- 'backspace':8,
- 'scrolllock':145,
- 'scroll_lock':145,
- 'scroll':145,
- 'capslock':20,
- 'caps_lock':20,
- 'caps':20,
- 'numlock':144,
- 'num_lock':144,
- 'num':144,
- 'pause':19,
- 'break':19,
- 'insert':45,
- 'home':36,
- 'delete':46,
- 'end':35,
- 'pageup':33,
- 'page_up':33,
- 'pu':33,
- 'pagedown':34,
- 'page_down':34,
- 'pd':34,
- 'left':37,
- 'up':38,
- 'right':39,
- 'down':40,
- 'f1':112,
- 'f2':113,
- 'f3':114,
- 'f4':115,
- 'f5':116,
- 'f6':117,
- 'f7':118,
- 'f8':119,
- 'f9':120,
- 'f10':121,
- 'f11':122,
- 'f12':123
- };
- var modifiers = {
- shift: { wanted:false, pressed:false},
- ctrl : { wanted:false, pressed:false},
- alt : { wanted:false, pressed:false},
- meta : { wanted:false, pressed:false} //Meta is Mac specific
- };
- if(e.ctrlKey) modifiers.ctrl.pressed = true;
- if(e.shiftKey) modifiers.shift.pressed = true;
- if(e.altKey) modifiers.alt.pressed = true;
- if(e.metaKey) modifiers.meta.pressed = true;
- for(var i=0; k=keys[i],i<keys.length; i++) {
- //Modifiers
- if(k == 'ctrl' || k == 'control') {
- kp++;
- modifiers.ctrl.wanted = true;
- } else if(k == 'shift') {
- kp++;
- modifiers.shift.wanted = true;
- } else if(k == 'alt') {
- kp++;
- modifiers.alt.wanted = true;
- } else if(k == 'meta') {
- kp++;
- modifiers.meta.wanted = true;
- } else if(k.length > 1) { //If it is a special key
- if(special_keys[k] == code) kp++;
- } else if(opt['keycode']) {
- if(opt['keycode'] == code) kp++;
- } else { //The special keys did not match
- if(character == k) kp++;
- else {
- if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
- character = shift_nums[character];
- if(character == k) kp++;
- }
- }
- }
- }
- if(kp == keys.length &&
- modifiers.ctrl.pressed == modifiers.ctrl.wanted &&
- modifiers.shift.pressed == modifiers.shift.wanted &&
- modifiers.alt.pressed == modifiers.alt.wanted &&
- modifiers.meta.pressed == modifiers.meta.wanted) {
- callback(e);
- if(!opt['propagate']) { //Stop the event
- //e.cancelBubble is supported by IE - this will kill the bubbling process.
- e.cancelBubble = true;
- e.returnValue = false;
- //e.stopPropagation works in Firefox.
- if (e.stopPropagation) {
- e.stopPropagation();
- e.preventDefault();
- }
- return false;
- }
- }
- }
- this.all_shortcuts[shortcut_combination] = {
- 'callback':func,
- 'target':ele,
- 'event': opt['type']
- };
- //Attach the function with the event
- if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
- else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
- else ele['on'+opt['type']] = func;
- },
- //Remove the shortcut - just specify the shortcut and I will remove the binding
- 'remove':function(shortcut_combination) {
- shortcut_combination = shortcut_combination.toLowerCase();
- var binding = this.all_shortcuts[shortcut_combination];
- delete(this.all_shortcuts[shortcut_combination])
- if(!binding) return;
- var type = binding['event'];
- var ele = binding['target'];
- var callback = binding['callback'];
- if(ele.detachEvent) ele.detachEvent('on'+type, callback);
- else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
- else ele['on'+type] = false;
- }
- }
- var getBoard = function() {
- URL = document.URL;
- return URL.split("/")[3];
- }
- var inlineImages = function()
- {
- // I Believe because I'm setting the src of the thumbnail to the full image right away,
- // it also causes the images to be prefetched
- $('.thread_image_box').each(function(index,currentImage) {
- if ($(currentImage).data("inline") != "true"){
- //$(currentImage).find('a').each(function() {
- $(currentImage).find('>a').each(function() {
- fullImage = $(this).attr('href');
- // if (!fullImage.match(/thumb(-[23])?/)){
- // if (!fullImage.match(/search(-[23])?/)){
- // if (!fullImage.match(/redirect?/)){
- // if (!fullImage.match(/download/)){
- if (fullImage.match(/\.webm$/)){ // Handle post webms
- $(currentImage).html('<div class="thread_image_box"><video width="125" style="float:left" name="media" loop muted '+autoplayVid+'><source src="'+fullImage+'" type="video/webm"></video></div>');
- }else if (!fullImage.match(/(\.pdf|\.swf)$/)){
- $(currentImage).find('img').each(function() {
- $(this).attr('src',fullImage);
- $(this).removeAttr('width');
- $(this).removeAttr('height');
- if ($(this).data("handled") != "true"){
- if ($(this).hasClass("thread_image")){ // Handle OP images
- $(this).data("handled","true");
- $(this).addClass("smallImageOP");
- $(this).click(function(e){
- if (!e.originalEvent.ctrlKey && e.which == 1){
- e.preventDefault();
- $($(this)["0"]["previousSibling"]).toggle(); // Toggle the Spoiler text
- $(this).toggleClass("smallImageOP");
- $(this).toggleClass("bigImage");
- }
- });
- }else{ // Handle post images
- $(this).addClass("smallImage");
- $(this).click(function(e){
- if (!e.originalEvent.ctrlKey && e.which == 1){
- e.preventDefault();
- $($(this)["0"]["previousSibling"]).toggle(); // Toggle the Spoiler text
- $(this).toggleClass("smallImage");
- $(this).toggleClass("bigImage");
- }
- });
- }
- }
- });
- }
- // }
- // }
- $(currentImage).data("inline","true");
- // }
- // }
- });
- }
- });
- $('video').each(function(index,currentVideo) {
- if ($(currentVideo).data("inline") != "true"){
- $(this).click(function(e){
- //e.preventDefault();
- if ($(this).hasClass("fullVideo")){
- this.muted =true;
- $(this).attr('width',"125");
- $(this).removeAttr('controls');
- $(this).removeClass("fullVideo");
- }else{
- $(this).removeAttr('width');
- $(this).attr('controls',"");
- $(this).addClass("fullVideo");
- this.muted =false;
- }
- });
- $(currentVideo).data("inline","true");
- }
- });
- }
- var inlineReplies = function(){
- $('article.post').each(function(index,currentPost) {
- if ($(currentPost).data("inline") != "true"){
- $(this).addClass("base");
- }
- $(currentPost).data("inline","true");
- });
- $('.post_backlink > .backlink').each(function(index,currentPost) {
- if ($(currentPost).data("inline") != "true"){
- $(this).on("click", function(e){
- if (!e.originalEvent.ctrlKey && e.which == 1){
- e.preventDefault();
- //e.stopPropagation();
- var postID = $(this).attr("data-post");
- var rootPostID = $(e["target"].closest('article.base')).attr('id');
- if ($(e["target"]).hasClass("inlined")){
- $(e["target"]).removeClass("inlined");
- $('.sub'+rootPostID).each(function(index,currentPost){
- $("#"+currentPost.id.substr(1)+".forwarded").removeClass("forwarded");
- });
- $('#i'+postID+'.sub'+rootPostID).remove();
- }else{
- $(e["target"]).addClass("inlined");
- $(e["target"]["parentNode"]["parentNode"]).after('<div class="inline sub'+rootPostID+'" id="i'+postID+'"></div>');
- $("#"+postID).addClass("forwarded").clone().removeClass("forwarded base post").attr("id","r"+postID).appendTo($("#i"+postID+'.sub'+rootPostID));
- $("#"+rootPostID+'.base .inline').each(function(index,currentPost){
- if (!$(this).hasClass('sub'+rootPostID)){
- $(this).attr("class","inline sub"+rootPostID);
- }
- });
- $("#i"+postID+" .post_wrapper").addClass("post_wrapperInline");
- }
- }
- });
- $(currentPost).data("inline","true")
- }
- });
- $('.text .backlink').each(function(index,currentPost) {
- if ($(currentPost).data("inline") != "true"){
- $(this).on("click", function(e){
- if (!e.originalEvent.ctrlKey && e.which == 1){
- e.preventDefault();
- //e.stopPropagation();
- var postID = $(this).attr("data-post");
- var rootPostID = $(e["target"].closest('article.base')).attr('id');
- if ($(e["target"]).hasClass("inlined")){
- $(e["target"]).removeClass("inlined");
- $('.sub'+rootPostID).each(function(index,currentPost){
- $("#"+currentPost.id.substr(1)+".forwarded").removeClass("forwarded");
- });
- $('#i'+postID+'.sub'+rootPostID).remove();
- }else{
- $(e["target"]).addClass("inlined");
- $(e["target"]["parentNode"]).after('<div class="inline sub'+rootPostID+'" id="i'+postID+'"></div>');
- $("#"+postID).addClass("forwarded").clone().removeClass("forwarded base post").attr("id","r"+postID).appendTo($("#i"+postID+'.sub'+rootPostID));
- $("#"+rootPostID+'.base .inline').each(function(index,currentPost){
- if (!$(this).hasClass('sub'+rootPostID)){
- $(this).attr("class","inline sub"+rootPostID);
- }
- });
- $("#i"+postID+" .post_wrapper").addClass("post_wrapperInline");
- }
- }
- });
- $(currentPost).data("inline","true")
- }
- });
- };
- function getSelectionText() {
- var text = "";
- if (window.getSelection) {
- text = window.getSelection().toString();
- } else if (document.selection && document.selection.type != "Control") {
- text = document.selection.createRange().text;
- }
- return text;
- }
- var postQuote = function(){
- $('.post_data > [data-function=quote]').each(function(index,currentPost) {
- if ($(currentPost).data("quotable") != "true"){
- $(this).removeAttr("data-function"); // Disable native quote function
- $(this).on("click", function(e){
- if (!e.originalEvent.ctrlKey && e.which == 1){
- e.preventDefault();
- var postnum = $(this)["0"].innerHTML;
- var input = document.getElementById('reply_chennodiscursus')
- if (input.selectionStart != undefined)
- {
- var startPos = input.selectionStart;
- var endPos = input.selectionEnd;
- var startText = input.value.substring(0, startPos);
- var endText = input.value.substring(startPos);
- var originalText = input.value;
- var selectedText = getSelectionText();
- if (selectedText == ""){
- var newText = startText +">>"+postnum+"\n"+ endText;
- }else{
- var newText = startText +">>"+postnum+"\n>"+ selectedText +"\n"+ endText;
- }
- document.getElementById('reply_chennodiscursus').value = originalText.replace(originalText,newText);
- }
- }
- });
- $(currentPost).data("quotable","true");
- }
- });
- };
- var hidePosts = function()
- {
- $('.pull-left').each(function(index, currentPost) {
- if ($(currentPost).hasClass('stub')) {
- $(currentPost).removeClass('stub')
- }
- });
- }
- var filter = function(){
- var sieveStrT0 = new RegExp("\\b("+filteredStringsT0.join("|")+")\\b"); // \b or (^|\s) works
- var sieveStrT1 = new RegExp("\\b("+filteredStringsT1.join("|")+")\\b","i"); // \b or (^|\s) works
- var sieveStrT2 = new RegExp("(^|\\s)("+filteredStringsT2.join("|")+")($|\\s)","i");
- var sieveTrip = new RegExp("("+filteredTrips.join("|")+")");
- var sieveName = new RegExp("("+filteredNames.join("|")+")");
- $('article.post').each(function(index,currentPost) {
- if ($(currentPost).data("filtered") != "true"){
- $(currentPost).data("filtered","true");
- var postText = $(this).find('.text').elemText();
- if (sieveTrip.test($(this).find('.post_tripcode').text()) || sieveName.test($(this).find('.post_author').text())){
- shitpostT2(currentPost, postText);
- }else if(sieveStrT0.test(postText)){
- //console.log(postText.match(sieveStrT0));
- shitpostT0(currentPost, postText);
- }else if (postText.length <= filterCharThreshold){
- if (sieveStrT1.test(postText)){
- //console.log(postText.match(sieveStrT1));
- shitpostT1(currentPost, postText);
- } else if (sieveStrT2.test(postText)){
- //console.log(postText.match(sieveStrT2));
- shitpostT2(currentPost, postText);
- }
- }
- }
- });
- }
- function shitpostT0(post, postText){
- $(post).addClass("shitpost");
- }
- function shitpostT1(post, postText){
- $(post).addClass("shitpost");
- }
- function shitpostT2(post, postText){
- $(post).removeClass('stub');
- $(post).find('.pull-left').removeClass('stub');
- var docID = $(post).find('.pull-left > button').attr("data-doc-id");
- $('.doc_id_'+docID).hide();
- $('.stub_doc_id_'+docID).show();
- }
- var embedImages = function() {
- $('.posts article').each(function(index, currentArticle){
- if ($(currentArticle).data('imgEmbed') != 'true'){
- var patt = new RegExp("http[s]?://("+imgSites+")/[^\"]*");
- var imgNum = imgNumMaster - $(currentArticle).find('.thread_image_box').length;
- $(currentArticle).find(".text > a, .text > .spoiler, .text > strong").each(function(index, currentLink){
- if (imgNum == 0) {
- return false;
- }
- var imglink = patt.exec($(this).html());
- if (imglink !== null){
- imgNum--;
- // var patt2 = new RegExp(escapeRegExp(imglink["0"]), 'g'); Can't see what this does, uncomment if things break again
- imglink["0"] = imglink["0"].replace(/.gifv/g, ".webm"); // Only tested to work with Imgur
- if ((/.webm/g).test(imglink["0"])){
- $(currentArticle).find(".post_wrapper").prepend('<div class="thread_image_box"><video width="125" style="float:left" name="media" loop muted '+autoplayVid+'><source src="'+imglink["0"]+'" type="video/webm"></video></div>');
- }else if ($(this).hasClass("spoiler")){
- $(currentArticle).find(".post_wrapper").prepend('<div class="thread_image_box"><a href="'+imglink["0"]+'" target="_blank" rel="noreferrer" class="thread_image_link"><div class="spoilerText">Spoiler</div><img src="'+imglink["0"]+'" class="lazyload post_image spoilerImage smallImage"></a></div>');
- }else{
- $(currentArticle).find(".post_wrapper").prepend('<div class="thread_image_box"><a href="'+imglink["0"]+'" target="_blank" rel="noreferrer" class="thread_image_link"><img src="'+imglink["0"]+'" class="lazyload post_image smallImage"></a></div>');
- }
- $(this).remove();
- }
- });
- $(currentArticle).data('imgEmbed', 'true');
- }
- });
- }
- function notifyMe() {
- if (!Notification) {
- alert('Please us a modern version of Chrome, Firefox, Opera or Firefox.');
- return;
- }
- if (Notification.permission !== "granted")
- Notification.requestPermission();
- var notification = new Notification('Notification title', {
- icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
- body: "Hey there! You've been notified!"
- });
- notification.onclick = function () {
- window.open("http://stackoverflow.com/a/13328397/1269037");
- }
- }
- var seenPosts = function(){$('article').each(function(index, currentArticle){$(currentArticle).data('seen','true')});}
- var newPosts = function() {
- $('article').each(function(index, currentArticle){
- if ($(currentArticle).data('seen') != 'true')
- {
- $(currentArticle).data('seen', 'true')
- newPostCount +=1
- }
- });
- if (windowFocus == true) newPostCount = 0
- document.title = "(" + newPostCount + ") " + DocumentTitle
- }
- var postCounter = function() {$(".rules_box").html("<h6>Posts: " + $('.post_wrapper').length + "/400 <br> Images: " + $(".thread_image_box").length + "/250</h6>" + rulesBox)}
- var bindShortcuts = function()
- {
- }
- var yourPosts = localStorage.yourPosts;
- if (yourPosts == undefined){
- yourPosts = {};
- console.log("Created post archive for the first time");
- } else {
- yourPosts = JSON.parse(localStorage.yourPosts);
- }
- window.addEventListener("beforeunload", function (e) {
- if (localStorage.yourPosts == undefined){
- localStorage.yourPosts = JSON.stringify(yourPosts);
- } else {
- localStorage.yourPosts = JSON.stringify($.extend(true, yourPosts, JSON.parse(localStorage.yourPosts)));
- }
- //var confirmationMessage = "\o/";
- //(e || window.event).returnValue = confirmationMessage; //Gecko + IE
- //return confirmationMessage; //Webkit, Safari, Chrome
- });
- function labelYourPosts(firstcall){
- $.each(queuedYouLabels, function(i, v){ // Parse all names on pageload and with each post submission
- $('#'+v+' .post_author').after('<span> (You)</span>');
- });
- queuedYouLabels = [];
- if (firstcall){ // Parse all backlinks present on pageload
- $.each(yourPosts[threadID], function(i,v){
- $('.backlink[data-post='+v+']').each(function(){
- if ($(this).data('linkedYou') != 'true'){
- this.textContent += ' (You)';
- $(this).data('linkedYou','true');
- }
- });
- });
- }
- }
- function labelNewPosts(response){
- var newPosts = Object.keys(response[threadID]["posts"]);
- $.each(newPosts, function(i,v){ // For each post returned by update
- $('#'+v+' .greentext > a').each(function(i, link){ // For each post content backlink
- var linkID = $(link).attr('data-post')
- if ($.inArray(linkID, yourPosts[threadID])+1){ // If the link points to your post
- link.textContent += ' (You)'; // Designate the link as such
- $('#'+linkID+' .post_backlink [data-post='+v+']')[0].textContent += ' (You)'; // And find your post's new reply backlink and designate it too
- }
- });
- });
- }
- var lastSubmittedContent;
- function postSubmitEvent(){
- if ($('#reply [type=submit]').length){
- window.MutationObserver = window.MutationObserver
- || window.WebKitMutationObserver
- || window.MozMutationObserver;
- var target = $('#reply [type=submit]')["0"],
- observer = new MutationObserver(function(mutation) {
- //console.log("Post Submit Event Triggered");
- lastSubmittedContent = $('#reply_chennodiscursus')[0].value;
- }),
- config = {
- attributes: true
- };
- observer.observe(target, config);
- }
- }
- $(document).ready(function(){
- //notifyMe();
- $('head').after('<script src="https://cdn.rawgit.com/madapaja/jquery.selection/master/src/jquery.selection.js"></script>'); // Pull in selection plugin (http://madapaja.github.io/jquery.selection/)
- $('head').after('<style type="text/css" id="FoolX-css">.bigImage{opacity: 1!important; max-width:100%;}.smallImage{max-width:125px; max-height:125px}.smallImageOP{max-width:250px; max-height:250px}.spoilerImage{opacity: 0.1}.spoilerText{position: relative; height: 0px; font-size: 19px; top: 47px;}.forwarded{display:none}.inline{border:1px solid; display: table; margin: 2px 0;}.inlined{opacity:0.5}.post_wrapper{border-right: 1px solid #cccccc;}.post_wrapperInline{border-right:0!important; border-bottom:0!important;}.quickReply{position: fixed; top: 0; right: 0; margin: 3px !important;}.shitpost{opacity: 0.3}</style>');
- windowFocus = true
- $(window).focus(function(){windowFocus = true; ThreadUpdate(features)})
- $(window).blur(function(){windowFocus = false})
- if (hideQROptions){
- $('#reply').toggleClass("showQROptions"); // Make options hidden in QR by default
- }
- threadID = $('#main > article[data-thread-num]').attr('id');
- if (yourPosts[threadID] == undefined){
- yourPosts[threadID] = [];
- } else {
- queuedYouLabels = yourPosts[threadID].slice(0);
- console.log(queuedYouLabels);
- }
- console.log(yourPosts);
- postSubmitEvent();
- $(document).ajaxComplete(function(event, request, settings) {
- //console.log(event);
- //console.log(request);
- //console.log(settings);
- if (request.responseText != ""){
- response = JSON.parse(request.responseText);
- }else{
- response = {"error":"No responseText"};
- }
- //console.log(response);
- if (response.error != undefined){
- console.log(response.error);
- }else{
- if (settings.type == "POST"){
- if (response.error == undefined ){
- for (var post in response[threadID]["posts"]) {
- //console.log(lastSubmittedContent);
- if(response[threadID]["posts"][post]["comment"].replace(/[\r\n]/g,'') == lastSubmittedContent.replace(/[\r\n]/g,'')){
- yourPosts[threadID].push(post);
- queuedYouLabels.push(post);
- //console.log(yourPosts);
- //console.log(queuedYouLabels);
- labelYourPosts();
- break;
- }
- }
- labelNewPosts(response);
- }else{
- console.log(response.error);
- }
- }else{
- if (response[threadID] != undefined){
- //console.log("GET");
- labelNewPosts(response);
- }else{
- console.log("Not in a thread");
- }
- }
- }
- });
- labelYourPosts(true); // First call, add (You) to page content
- });
- var executeShortcut = function(shortcut) {
- //console.log(shortcut);
- var input = document.getElementById('reply_chennodiscursus');
- if (input.selectionStart != undefined){
- $('#reply_chennodiscursus').selection('insert', {
- text: "["+shortcut+"]",
- mode: 'before'
- });
- $('#reply_chennodiscursus').selection('insert', {
- text: "[/"+shortcut+"]",
- mode: 'after'
- });
- }
- }
- function quickReply(){
- $('#reply').toggleClass("quickReply");
- $('#reply fieldset > div:nth-child(1)').css("width","");
- if ($('#reply').hasClass("showQROptions")){
- $('#reply fieldset > div:nth-child(2)').toggle();
- }
- }
- function quickReplyOptions(){
- $('#reply').toggleClass("showQROptions");
- $('#reply.quickReply fieldset > div:nth-child(2)').toggle();
- }
- $(function(){
- shortcut.add("ctrl+s", function(){ executeShortcut("spoiler")});
- shortcut.add("ctrl+i", function(){ executeShortcut("i")});
- shortcut.add("ctrl+b", function(){ executeShortcut("b")});
- shortcut.add("ctrl+u", function(){ executeShortcut("u")});
- shortcut.add("q", function(){quickReply()}, {"disable_in_input":true});
- shortcut.add("ctrl+q", function(){quickReplyOptions()}, {"disable_in_input":false});
- seenPosts();
- ThreadUpdate(features);
- getBoard();
- bindShortcuts();
- window.setInterval( function(){ ThreadUpdate(features); }, 500 );
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement