// ==UserScript==
// @name Dynasty Thingifier
// @namespace Alice Cheshire
// @include http://dynasty-scans.com/*
// @exclude http://dynasty-scans.com/system/images_images/*
// @version 2.0.6.5
// @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 = `
<div id="thingifier-bbcode">
<div class="thingifier-bbcode-first-row"><input type="button" id="thingifier-bbcode-quote" value="Quote">
<input type="button" id="thingifier-bbcode-link" value="Link">
<input type="button" id="thingifier-bbcode-image" value="Image">
<input type="button" id="thingifier-bbcode-spoiler" value="Spoiler">
<input type="button" id="thingifier-bbcode-ul" value="List">
<input type="button" id="thingifier-bbcode-ol" value="Numbered List">
<input type="button" id="thingifier-bbcode-italics" value="Italics">
<input type="button" id="thingifier-bbcode-bold" value="Bold">
</div>
<div class="thingifier-bbcode-second-row">
<input type="button" id="thingifier-bbcode-tag" value="Tags">
<input type="button" id="thingifier-bbcode-hr" value="Horizontal Rule">
<input type="button" id="thingifier-bbcode-codeblock" value="Code Block">
<input type="button" id="thingifier-bbcode-h1" value="H1">
<input type="button" id="thingifier-bbcode-h2" value="H2">
<input type="button" id="thingifier-bbcode-h3" value="H3">
<input type="button" id="thingifier-bbcode-h4" value="H4">
<input type="button" id="thingifier-bbcode-h5" value="H5">
<input type="button" id="thingifier-bbcode-h6" value="H6">
</div>
</div>`, //The html code for our bbcode buttons
quickreply;
init();
//Initialize Script
function init() {
//Load our config
configload();
//Populate Menu
$('body').append(`
<style>
#thingifier * { padding: 0; margin: 0; }
#thingifier {
float: left;
position: fixed;
top: 45%;
z-index: 1000000;
}
#thingifier-options {
border: 1px solid black;
padding: 8px;
background: aliceblue;
border-bottom-right-radius: 6px;
border-left-width: 0;
}
#thingifier-options ul { list-style-type: none; margin-left: -4px;}
#thingifier-options ul > li { vertical-align: middle; }
#thingifier ul li input { padding-right: 4px; }
#thingifier-font-size { width: 96px; }
#thingifier-toggle-button {
position: absolute;
top: 0;
left: calc(100% - 1px);
width: 24px;
height: 24px;
border: 1px solid black;
background-color: aliceblue;
color: red;
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
border-left-width: 0;
}
.spoilers-disabled {
background: #666 none repeat scroll 0% 0%;
color: #fff;
}
.navbar-fixed {
position: fixed;
z-index: 1000;
width: 1210px;
}
.pull-right-fixed, .nav-collapse-fixed {
float: right;
}
.nav-padding {
height: 60px;
width: 1210px;
}
.forum_post_one {
font-size: 10px !important;
line-height: 12px !important;
}
.forum_post_two {
font-size: 12px !important;
line-height: 15px !important;
}
.forum_post_three {
font-size: 16px !important;
line-height: 19px !important;
}
.forum_post_four {
font-size: 20px !important;
line-height: 23px !important;
}
.forum_post_five {
font-size: 25px !important;
line-height: 28px !important;
}
#thingifier-bbcode {
margin-bottom: 6px;
}
#thingifier-quickreply {
width: 100% !important;
background-color: aliceblue !important;
display: inline-block;
padding: 4px;
padding-bottom: 8px;
border-radius: 8px;
margin-bottom: 6px;
}
#magnifier {
visibility: hidden;
min-width: 256px;
min-height: 256px;
width: 25vmin;
height: 25vmin;
position: absolute;
border: 1px solid grey;
background-color: rgba(0, 0, 0, 0.1);
border-radius: 50%;
background-repeat: no-repeat;
pointer-events: none;
z-index: 1000000;
}
</style>
<div id="thingifier">
<div id="thingifier-options">
<ul>
<li><input type="checkbox" id="thingifier-unhide-spoilers"> Unhide spoilers</li>
<li><input type="checkbox" id="thingifier-fixed-navbar"> Fixed navbar</li>
<li><input type="checkbox" id="thingifier-pagination"> Add page selector to top of page</li>
<li><input type="checkbox" id="thingifier-bbcode-buttons"> Add quick reply and post page bbcode buttons</li>
<li><input type="checkbox" id="thingifier-quote-to-quickreply"> Quote to quick reply instead of new post page</li>
<li><input type="checkbox" id="thingifier-quote-move-quickreply"> Move quick reply to under quoted post</li>
<li><input type="checkbox" id="thingifier-magnifier" tooltip="Press Z or middle mouse click"> Magnifier on reader and image pages</li>
<li><input type="range" id="thingifier-font-size" min="1" max="5"> Change font size <input type="button" id="thingifier-reset-font" value="Reset Font Size"></li>
<li><a href="http://dynasty-scans.com/forum/posts?user_id=${yourid}" id="thingifier-ownposts"> Your posts</a></li>
<li><input type="text" id="useridinput"><input type="button" value="Submit user id" id="useridsubmit"></li>
<li><input type="button" id="thingifier-clear" value="Clear stored data"></li>
</ul>
</div>
<div id="thingified-toggle"><input type="button" id="thingifier-toggle-button" value="X"></div>
</div>
`);
//Setup own posts link stuff
$('#useridinput').hide();
$('#useridsubmit').hide();
if (GM_getValue("youruserid", "Not Set") == "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!";
}
}
}
//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);
$("<div class=\"nav-padding\"></div>").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('<div class=\"tmp\">').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");
});
$('#thingifier-magnifier').click(function() {
GM_setValue('magnifier', $('#thingifier-magnifier').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");
GM_deleteValue("magnifier");
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"));
console.log(GM_getValue("magnifier", "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();
}
//Check if the magnifier option is enabled
if (!!GM_getValue('magnifier', null)) {
$('#thingifier-magnifier').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 <textarea>
var txtarea = document.getElementById("forum_post_message");
// obtain the index of the first selected character
var start = txtarea.selectionStart;
// obtain the index of the last selected character
var finish = txtarea.selectionEnd;
// obtain the selected text
sel = txtarea.value.substring(start, finish);
txtbegin = txtarea.value.substring(0, start);
txtend = txtarea.value.substring(finish);
// do something with the selected content
}
$('#thingifier-bbcode-quote').click(function() {
texttmp = texttmp.replace(/(^\S)/gm, "> $1");
bbcode_format();
});
$('#thingifier-bbcode-link').click(function() {
if (sel.length === 0) {
texttmp = texttmp.replace(/(.*)/gm, "[]($1)");
} else {
texttmp = texttmp.replace(/(.+)/gm, "[]($1)");
}
bbcode_format();
});
$('#thingifier-bbcode-image').click(function() {
if (sel.length === 0) {
texttmp = texttmp.replace(/(.*)/gm, "");
} else {
texttmp = texttmp.replace(/(.+)/gm, "");
}
bbcode_format();
});
$('#thingifier-bbcode-spoiler').click(function() {
if (sel.length === 0) {
texttmp = texttmp.replace(/(.*)/gm, "==$1==");
} else {
texttmp = texttmp.replace(/(.+)/gm, "==$1==");
}
bbcode_format();
});
$('#thingifier-bbcode-hr').click(function() {
texttmp = texttmp.replace(/(^\S)/gm, "\n***\n $1");
bbcode_format();
});
$('#thingifier-bbcode-ul').click(function() {
texttmp = texttmp.replace(/(^\S)/gm, " * $1");
bbcode_format();
});
$('#thingifier-bbcode-ol').click(function() {
texttmp = texttmp.replace(/(^\S)/gm, " 1. $1");
bbcode_format();
});
$('#thingifier-bbcode-italics').click(function() {
if (sel.length === 0) {
texttmp = texttmp.replace(/(.*)/gm, "*$1*");
} else {
texttmp = texttmp.replace(/(.+)/gm, "*$1*");
}
bbcode_format();
});
$('#thingifier-bbcode-bold').click(function() {
if (sel.length === 0) {
texttmp = texttmp.replace(/(.*)/gm, "**$1**");
} else {
texttmp = texttmp.replace(/(.+)/gm, "**$1**");
}
bbcode_format();
});
$('#thingifier-bbcode-tag').click(function() {
if (sel.length === 0) {
texttmp = texttmp.replace(/(.*)/gm, "`$1`");
} else {
texttmp = texttmp.replace(/(.+)/gm, "`$1`");
}
bbcode_format();
});
$('#thingifier-bbcode-codeblock').click(function() {
if (sel.length === 0) {
texttmp = texttmp.replace(/(.*)/gm, " $1 ");
} else {
texttmp = texttmp.replace(/(.+)/gm, " $1 ");
}
bbcode_format();
});
$('#thingifier-bbcode-h1').click(function() {
if (sel.length === 0) {
texttmp = texttmp.replace(/(.*)/gm, "# $1 #");
} else {
texttmp = texttmp.replace(/(.+)/gm, "# $1 #");
}
bbcode_format();
});
$('#thingifier-bbcode-h2').click(function() {
if (sel.length === 0) {
texttmp = texttmp.replace(/(.*)/gm, "## $1 ##");
} else {
texttmp = texttmp.replace(/(.+)/gm, "## $1 ##");
}
bbcode_format();
});
$('#thingifier-bbcode-h3').click(function() {
if (sel.length === 0) {
texttmp = texttmp.replace(/(.*)/gm, "### $1 ###");
} else {
texttmp = texttmp.replace(/(.+)/gm, "### $1 ###");
}
bbcode_format();
});
$('#thingifier-bbcode-h4').click(function() {
if (sel.length === 0) {
texttmp = texttmp.replace(/(.*)/gm, "#### $1 ####");
} else {
texttmp = texttmp.replace(/(.+)/gm, "#### $1 ####");
}
bbcode_format();
});
$('#thingifier-bbcode-h5').click(function() {
if (sel.length === 0) {
texttmp = texttmp.replace(/(.*)/gm, "##### $1 #####");
} else {
texttmp = texttmp.replace(/(.+)/gm, "##### $1 #####");
}
bbcode_format();
});
$('#thingifier-bbcode-h6').click(function() {
if (sel.length === 0) {
texttmp = texttmp.replace(/(.*)/gm, "###### $1 ######");
} else {
texttmp = texttmp.replace(/(.+)/gm, "###### $1 ######");
}
bbcode_format();
});
function bbcode_format() {
var tmp = txtbegin + texttmp.replace(/\[BBCODE-HERE\]/, tmp) + txtend;
$('#forum_post_message').val(tmp);
}
}
$(document).ready(function() {
if (isuserpostsurl.match(/http:\/\/dynasty-scans.com\/forum\/posts\?user_id=\d+/)) {
isuserpostsurl = isuserpostsurl.replace(/\d+/, ""); //Replaces the user id in the url
}
for (var i = 0; i < postcount; i++){
counter = i;
var id = postids[i].toString(); //Temporarily store the post id under the key of 'i' into a variable to use in our next bit
if ($('#thingifier-quote-to-quickreply').is(":checked")) {
GM_setValue('quote2quickreply', $('#thingifier-quote-to-quickreply').is(":checked"));
var tmp = $('.forum_post .info .row .actions').find("span:first-child a");
var tmphref = tmp.attr('href');
var urltmp = document.location.toString();
urltmp = urltmp.replace(/(http:\/\/dynasty-scans\.com\/forum\/topics\/)(\d+)(.+)/, "$2");
$('.forum_post .info .row .actions:eq(' + counter + ')').prepend("<input type=\"button\" class=\"postquote\" id=\"" + tmphref + "\" value=\"Quick Quote\" name=\"post_" + counter + "\">");
id = id.replace(/forum_post_/, "");
}
if(isuserpostsurl !== "http://dynasty-scans.com/forum/posts?user_id=") {
//If we're not on the user posts page then we turn all post timestamps on a page into an anchor link
$(".time").eq(i).replaceWith("<div class=\"span5 time\"><a class=\"timelink\" href=\"" + pageurl + "#forum_post_" + id + "\">" + $(".time").eq(i).text() + "</a></div>");
}
counter++;
}
$('input.postquote').mouseup(function(e) {
document.getElementById('forum_post_message').value = "";
var postid = $($(this).parents()[3]).attr('id');
var quoteid = postid; //Gets the id of the .forum_post parent
quoteid = "#" + quoteid; //Adds a url anchor sign to the id
quoteid = quoteid.toString(); //Converts it to a string to make sure it cooperates
GM_setValue("quoteid", pageurl + quoteid);
var quotename = $.trim($(quoteid).find(".user").text().replace(/Staff|Moderator|Uploader/, "")); //Retrieve the quoted user's name
//For staff, mods, and uploaders find and remove their title, then trim the whitespace/newlines off the beginning and end
GM_setValue("quotename", quotename);
postid = postid.replace(/forum_post_/, "");
var threadid = document.location.toString();
threadid = threadid.replace(/(http:\/\/dynasty-scans\.com\/forum\/topics\/)(\d+)(\S+)/, "$2");
var postpath = "http://dynasty-scans.com/forum/posts/new?quote_id=\"" + postid +"\"&topic_id=\"" + threadid + "\"";
postpath = postpath.replace(/"/g, "");
postid = postid.replace(/post_/, "");
getpost(postpath, postid);
if (quickreply) {
var replybox;
if ($("#thingifier-quickreply").length < 1) {
$("#new_forum_post").wrap("<div id=\"thingifier-quickreply\"></div>");
}
if (!replybox) {
replybox = $("#thingifier-quickreply").detach();
replybox.appendTo(quoteid);
replybox = null;
}
}
if ($("#thingifier-quickreply").offset().top > window.pageYOffset + document.documentElement.clientHeight || $("#thingifier-quickreply").offset().top < window.pageYOffset) {
$(document).scrollTop($("#thingifier-quickreply").offset().top - $('div.nav-padding').height());
}
});
//Do this if we click the quote button
$('a').mouseup(function(e) { //When we click a link run this code
if ($(e.target).text() == "Quote") { //Make sure that the clicked link is the quote button
var quoteid = $(e.target).parents(); //Gets all the parent elements of our link
quoteid = quoteid[4]; //Selects the fourth parent which is the .forum_post parent of the link
quoteid = $(quoteid).attr('id'); //Gets the id of the .forum_post parent
quoteid = "#" + quoteid; //Adds a url anchor sign to the id
quoteid = quoteid.toString(); //Converts it to a string to make sure it cooperates
GM_setValue("quoteid", pageurl + quoteid);
var quotename = $(quoteid).find(".user").text(); //Retrieve the quoted user's name
quotename = quotename.replace(/Staff|Moderator|Uploader/, ""); //For staff, mods, and uploaders find and remove their title
quotename = $.trim(quotename); //Trim the whitespace/newlines off the beginning and end
GM_setValue("quotename", quotename);
} else { /*This is where code would run if we were doing anything for clicking other links*/ }
});
//Check that the current page is the new posts page
if (pageurl.match(/posts\/new/)) {
var post = GM_getValue("quoteid", false);
var username = GM_getValue("quotename", false);
if (!!post && !!username) {
quote = "> [" + username + "](" + post + ") \n> ";
var message = "\n" + $('#forum_post_message').val();
$('#forum_post_message').val(quote + message);
}
}
//Reset our quoteid and quotename values if we preview our post.
$('input[value="Preview Post"]').click(function(e) {
GM_deleteValue("quoteid");
GM_deleteValue("quotename");
});
//Reset our quoteid and quotename values if we create our post.
$('input[value="Create Post"]').click(function(e) {
GM_deleteValue("quoteid");
GM_deleteValue("quotename");
});
//Insert "unread posts" button after thread link in manga viewer
if (pageurl.match(/chapters/)) {
var mangathread = '<a class="btn btn-mini" title="View latest unread post in thread"href="' + $('div.btn-toolbar div.btn-group:first-child a.btn:first-child').attr('href') + '/unread"><i class="icon-comment"></i>Unread</a>';
$(mangathread).insertAfter('div.btn-toolbar div.btn-group:first-child a.btn:first-child');
}
//Insert last post link to read threads
if (pageurl.match(/\/forum(?!\/topics)/)) {
var elements = $('div.forum_topic').length;
for (i = 0; i < elements; i++) {
if ($('div.forum_topic:eq(' + i + ')').not('.unread').length) {
var link = '<a href="' + $('div.forum_topic:eq(' + i + ') a.subject').attr('href') + '/unread" style="margin-left:10px;"><i class="icon-comment"></i>Last Post</a>';
//Check if thread has multiple pages. If so place link after pagination, otherwise place it right after the thread link
if ($('div.forum_topic:eq(' + i + ')').find('span.pages').length !== 0) {
$(link).insertAfter('div.forum_topic:eq(' + i + ') span.pages');
} else {
$(link).insertAfter('div.forum_topic:eq(' + i + ') a.subject');
}
}
}
}
//Magnifier Function
var magY, magX, magShown = 0, imgPath = "none", zoom = 500, zoomFactor = zoom / 100, pWidth = 0, pHeight = 0, pOffset = 0, magZ = false;
var updater = window.setInterval(update, 100);
if (pageurl.match(/chapters/) || pageurl.match(/images/) && GM_getValue("magnifier", false)) {
console.log("Viewing a chapter or image");
$('body').append('<div id="magnifier"></div>');
}
$(document).mousemove(function(e) {
if (GM_getValue("magnifier", false)) {
magY = e.pageY;
magX = e.pageX;
$('#magnifier').offset({ top: magY - ($('#magnifier').height() / 2), left: magX - ($('#magnifier').width() / 2) });
var backLeft = ((-magX + pOffset.left) * zoomFactor) + 130;
var backTop = ((-magY + pOffset.top) * zoomFactor) + 130;
$('#magnifier').css("background-position", backLeft + "px " + backTop + "px");
}
});
$(document).mousedown(function(e) {
if (GM_getValue("magnifier", false)) {
var tmp = $(e.target).parent()[0];
if (tmp.className === "image" && pageurl.match(/images/)) {
tmp = tmp.className;
} else if (tmp.id === "image" && pageurl.match(/chapters/)) {
tmp = tmp.id;
} else {
tmp = false;
}
tmp = !!tmp;
if (e.which === 2 && tmp !== false) {
e.preventDefault();
}
//console.log(e.which);
magnifier(tmp, e.which);
}
});
$(document).keydown(function(e) {
if (GM_getValue("magnifier", false)) {
if (e.which == 90) {
e.preventDefault();
magZ = true;
} else {
magZ = false;
}
if (magZ === true) {
magnifier(magZ, 2);
}
}
});
function magnifier(check, which) {
if (GM_getValue("magnifier", false)) {
if (!!check) {
magShown = magShown ? 0 : 1;
}
//console.log(!!magShown + "\n" + !!check);
if (!!magShown && !!check && which === 2) {
$('#magnifier').css("visibility", "visible");
$('*').css("cursor", "none");
} else {
$('#magnifier').css("visibility", "hidden");
$('*').css("cursor", "auto");
$('a').css("cursor", "pointer");
$('a *').css("cursor", "pointer");
$('span.left').css("cursor", "pointer");
$('span.right').css("cursor", "pointer");
}
}
}
function update() {
if (GM_getValue("magnifier", false)) {
pOffset = $('#image img').offset() || $('div.image img').offset();
pWidth = $('div#image').width() || $('div.image img').width();
pHeight = $('div#image').height() || $('div.image img').height();
imgPath = $('#image img').attr('src') || $('div.image img').attr('src') || "none";
if (imgPath !== "none") {
imgPath = imgPath.replace(/<img src=\"(.+)\">/, '$1');
$('#magnifier').css("background-image", "url(" + imgPath + ")");
$('#magnifier').css("background-size", (pWidth * zoomFactor) + "px " + (pHeight * zoomFactor) + "px");
}
}
}
});//$(document).ready() end
function getpost(postpath, postid) {
var message = "";
$.ajax({
type: "GET",
url: postpath,
dataType: "text",
timeout: 10000,
cache: false
})
.done(function(data) {
quote[postid] = data.replace(/([\u0000-\uffff]+<textarea .+ id="forum_post_message".+>)([\u0000-\uffff]+)(<\/textarea>[\u0000-\uffff]+)/, "$2");
quote[postid] = htmlDecode(quote[postid]);
$('#forum_post_message').val(quote[postid]);
var post = GM_getValue("quoteid");
var username = GM_getValue("quotename");
quote = "> [" + username + "](" + post + ") \n> ";
message = htmlDecode(data.replace(/([\u0000-\uffff]+<textarea .+ id="forum_post_message".+>)([\u0000-\uffff]+)(<\/textarea>[\u0000-\uffff]+)/, "$2"));
$('#forum_post_message').val(quote + message);
})
.fail(function() {
console.log("error");
});
}
function htmlDecode(input){
var e = document.createElement('div');
e.innerHTML = input;
return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}
})();