// ==UserScript== // @name Dynasty Thingifier // @namespace Alice Cheshire // @include http://dynasty-scans.com/* // @exclude http://dynasty-scans.com/system/images_images/* // @version 2.0 // @require http://code.jquery.com/jquery-2.1.4.min.js // @description Adds post links and quote stuff to Dynasty forums // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant GM_listValue // @run-at document-end // ==/UserScript== (function() { "use strict"; var pageurl = document.location.toString().replace(/(#.+)/, ""), //Stores page url and removes any anchors from the stored url so we don't get issues with multiple anchors showing up isuserpostsurl = document.location.toString(), //Stores the address variable a second time for use in a different function postids = [], //Initializes a blank array for the postids quote = [], //Initializes blank array for quotes postcount = 0, //Counter to keep track of how many posts are on the current page counter = 0, configmenustate = GM_getValue("configmenustate", true), //Init our menu state's varaiable yourid = GM_getValue("youruserid"), //Set our user id variable fontsize = [3, "one", "two", "three", "four", "five"], bbcode_menu = '
', //The html code for our bbcode buttons quickreply; init(); //Initialize Script function init() { //Load our config configload(); //Populate Menu $('body').append(''); $('body').prepend('
'); $('#thingifier').append('
'); $('#thingifier-options').append(''); $('#thingifier-options ul').append('
  • Fixed navbar
  • '); $('#thingifier-options ul').append('
  • Add page selector to top of page
  • '); $('#thingifier-options ul').append('
  • Add quick reply and post page bbcode buttons
  • '); $('#thingifier-options ul').append('
  • Quote to quick reply instead of new post page
  • '); $('#thingifier-options ul').append('
  • Move quick reply to under quoted post
  • '); $('#thingifier-options ul').append('
  • Change font size
  • '); $('#thingifier-options ul').append('
  • Your posts
  • '); $('#thingifier-options ul').append('
  • '); $('#thingifier-options ul').append('
  • '); $('#thingifier').append('
    '); //Setup own posts link stuff $('#useridinput').hide(); $('#useridsubmit').hide(); if (GM_getValue("youruserid", "Not Set") == "Not Set") { //GM_getValue("youruserid", "Not Set"); $('#thingifier-ownposts').hide(); $('#useridinput').show(); $('#useridsubmit').show(); setuserid(); } //Check we're viewing a thread if (pageurl.match(/forum\/topics/)) { $('.forum_post').each(function() { postids.push(this.id); //For each element of the class forum_post push the element's id to our postids array }); $('.time').each(function(i, obj) { postcount++; //This is where we actually count how many posts are on the page }); //Retrieve your user id if (GM_getValue("youruserid", "Not set").match(/\d+/)) { console.log("Retrieved user id: " + GM_getValue("youruserid")); yourid = "http://dynasty-scans.com/forum/posts?user_id=" + GM_getValue("youruserid"); } else { console.log("User id not set!"); yourid = "Your user id isn't set!"; } //console.log(JSON.stringify(postids)); } } //Set user ID for own posts link function setuserid() { $('input#useridsubmit').click(function () { console.log("User id submitted"); if($("input#useridinput").val().match(/^\d+$/)) { GM_setValue("youruserid", $('input#useridinput').val()); $('#useridinput').hide(); $('#useridsubmit').hide(); $('#thingifier-ownposts').show(); $('#thingifier-ownposts').attr('href', "http://dynasty-scans.com/forum/posts?user_id=" + GM_getValue("youruserid")); } else { GM_deleteValue("youruserid"); $("input#useridinput").val(); $('input#useridinput').val("Invalid user id!"); } }); } //Menu close/open $('input#thingifier-toggle-button').click(function() { menuclose("click"); }); //Unhide spoilers option $('#thingifier-unhide-spoilers').click(function() { if ($('#thingifier-unhide-spoilers').is(":checked")) { $('.spoilers').addClass('spoilers-disabled'); } else { $('.spoilers').removeClass('spoilers-disabled'); } GM_setValue("spoilers", $('#thingifier-unhide-spoilers').is(":checked")); }); //Fixed navbar option $('#thingifier-fixed-navbar').click(function() { if ($('#thingifier-fixed-navbar').is(":checked")) { GM_setValue("navbar", $('#thingifier-fixed-navbar').is(":checked")); $('.navbar').addClass('navbar-fixed'); $('div.forum_post').css("padding-top", 40); $("
    ").insertAfter(".navbar"); } else { GM_setValue("navbar", $('#thingifier-fixed-navbar').is(":checked")); $('.navbar').removeClass('navbar-fixed'); $('div.forum_post').css("padding-top", 0); $('div.nav-padding').remove(); } }); //Pagination option $('#thingifier-pagination').click(function() { if ($('#thingifier-pagination').is(":checked")) { GM_setValue("pagination", $('#thingifier-pagination').is(":checked")); $("div.pagination").wrap('
    ').parent().html(); var tmp = $('div.tmp').html(); $("div.pagination").unwrap(); $('#main').prepend(tmp); } else { GM_setValue("pagination", $('#thingifier-pagination').is(":checked")); $("div.pagination").first().remove(); } }); //Add bbcode buttons to post page and quick reply $('#thingifier-bbcode-buttons').click(function() { if ($('#thingifier-bbcode-buttons').is(":checked")) { GM_setValue("bbcode", $('#thingifier-bbcode-buttons').is(":checked")); $("#forum_post_message").parent().prepend(bbcode_menu); } else { GM_setValue("bbcode", $('#thingifier-bbcode-buttons').is(":checked")); $("div#thingifier-bbcode").remove(); } }); //Move the quick reply box to the current post $('#thingifier-quote-move-quickreply').click(function() { GM_setValue('movequickreply', $('#thingifier-quote-move-quickreply').is(":checked")); quickreply = $('#thingifier-quote-move-quickreply').is(":checked"); }); //Font size slider $('#thingifier-font-size').on('input', function() { fontsize[0] = parseInt($(this).val()); $('.message *').removeClass('forum_post_one'); $('.message *').removeClass('forum_post_two'); $('.message *').removeClass('forum_post_three'); $('.message *').removeClass('forum_post_four'); $('.message *').removeClass('forum_post_five'); $('.message *').addClass('forum_post_' + fontsize[fontsize[0]]); GM_setValue('fontsize', fontsize[0]); }); //Reset font size $('#thingifier-reset-font').click(function() { $('.message *').removeClass('forum_post_one'); $('.message *').removeClass('forum_post_two'); $('.message *').removeClass('forum_post_three'); $('.message *').removeClass('forum_post_four'); $('.message *').removeClass('forum_post_five'); $('#thingifier-font-size').val(3); GM_deleteValue('fontsize'); }); //Clear saved data $('#thingifier-clear').click(function() { var x = window.confirm("Are you sure you want to clear your stored data?"); if (x) { GM_deleteValue("youruserid"); GM_deleteValue("quoteid"); GM_deleteValue("quotename"); GM_deleteValue("spoilers"); GM_deleteValue("navbar"); GM_deleteValue("pagination"); GM_deleteValue("bbcode"); GM_deleteValue("quote2quickreply"); console.log(GM_getValue("youruserid", "Not set")); console.log(GM_getValue("quoteid", "Not set")); console.log(GM_getValue("quotename", "Not set")); console.log(GM_getValue("spoilers", "Not set")); console.log(GM_getValue("navbar", "Not set")); console.log(GM_getValue("pagination", "Not set")); console.log(GM_getValue("bbcode", "Not set")); console.log(GM_getValue("quote2quickreply", "Not set")); document.location.reload(true); } else { console.log("Decided against it"); } }); //Load our config function configload() { //Only run once the page is loaded $(document).ready(function() { //Deal with our current menu state menuclose("load"); //Check if spoilers are unhidden if (!!GM_getValue("spoilers", false)) { $('#thingifier-unhide-spoilers').click(); } //Check if the fixed navbar is enabled if (!!GM_getValue("navbar", false)) { $('#thingifier-fixed-navbar').click(); } //Check if pagination option is enabled if (!!GM_getValue("pagination", false)) { $('#thingifier-pagination').click(); } //Check if we've changed the font size and retrieve it fontsize[0] = GM_getValue('fontsize', null); if (fontsize[0] !== null) { $('#thingifier-font-size').val(fontsize[0]); $('.message *').addClass('forum_post_' + fontsize[fontsize[0]]); } //Check if bbcode buttons are enabled if (!!GM_getValue('bbcode', null)) { $('#thingifier-bbcode-buttons').click(); } //Check if quote to quick reply option is enabled if (!!GM_getValue('quote2quickreply', null)) { $('#thingifier-quote-to-quickreply').click(); } //Check if the move quick reply box option is enabled if (!!GM_getValue('movequickreply', null)) { $('#thingifier-quote-move-quickreply').click(); } bbcode(); }); } function menuclose(sender) { //Only runs when loading a page if (sender === "load") { configmenustate = GM_getValue("configmenustate", true); //Load our menu state if (!configmenustate) { //If it's true collapse the menu $("#thingifier-options").animate({width:'toggle', height:'toggle'},0); } //Runs when clicking the button } else if (sender === "click") { configmenustate = !!configmenustate ? false : true; //XOR our menu state, can also use ^= $("#thingifier-options").animate({width:'toggle', height:'toggle'},350); //Toggle the menu GM_setValue("configmenustate", !!configmenustate); //Store the value } //Controls the button's icon if (!configmenustate) { $('#thingifier-toggle-button').val('▶'); } else { $('#thingifier-toggle-button').val('◀'); } } function bbcode() { var texttmp, sel, posttmp, regextmp, txtbegin, txtend; $('#forum_post_message').mousedown(function() { $('body').mouseup(function() { getSel(); texttmp = sel; posttmp = $('#forum_post_message').val(); regextmp = new RegExp("("+texttmp.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&")+")"); posttmp = posttmp.replace(regextmp, "[BBCODE-HERE]"); }); }); function getSel() // javascript { // obtain the object reference for the