User:Joeytje50/Drop logs.user.js

// ==UserScript== // @name          RuneScape Drop Logs // @description   Keep track of your drops easily // @include       *runescape.com* // @version       2.0 // ==/UserScript==

//Importing JQuery var load,execute,loadAndExecute;load=function(a,b,c){var d;d=document.createElement("script"),d.setAttribute("src",a),b!=null&&d.addEventListener("load",b),c!=null&&d.addEventListener("error",c),document.body.appendChild(d);return d},execute=function(a){var b,c;typeof a=="function"?b="("+a+");":b=a,c=document.createElement("script"),c.textContent=b,document.body.appendChild(c);return c},loadAndExecute=function(a,b){return load(a,function{return execute(b)})}; loadAndExecute('https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js', function { //End importing JQuery

function safeRegex(string) { var result = string.replace(/\||\{|\[|\(|\)|\}|\]|\^|\$|\?|\.|\\|\+/g, '\\$&'); return result; }

$(document).ready(function {	$('#menu').before('  default wikicode  ');	$('#dropLogForm').submit(function { var input = $('#dropLogEnter').val.replace(/^ *| *$/g, ''); var log = $('#dropLog').val; if (input.length != 0 && !(input.match(/^kill.*/))) {

var inputmin = input.replace(/^-/, ''); var exists = log.match(RegExp('^' + safeRegex(inputmin) + ': ', 'm')) ? true : false; var replace = new RegExp('(' + safeRegex(input) + '): ([0-9]+)'); var replacemin = new RegExp('(\n?)(' + safeRegex(inputmin) + '): ([0-9]+)'); var empty = log.length != 0 ? '\n' : ''; var addup = input.match(/^-.+/) ? -1 : 1			var cur = exists ? parseFloat((log.match(replacemin)).join().replace(inputmin + ': ', )) : 0; if (exists) { if (cur == 1 && addup == -1) { $('#dropLog').val(log.replace(replacemin, '')); } else { $('#dropLog').val(log.replace(replacemin, '$1$2: ' + (cur + addup))); }			} else if (addup != -1) { $('#dropLog').val(log + empty + input + ': 1') }

log = $('#dropLog').val;

if (!(input.match(/^-.*/))) { if (log.match('kills: ')) { $('#dropLog').val('kills: 0\n' + log); var kills = log.match('kills: ') ? parseFloat((log.match(/kills: [0-9]+/)).join().replace('kills: ', )) + 1 : 1; $('#dropLog').val(log.replace(/kills: [0-9]+/, 'kills: ' + kills)); } else { $('#dropLog').val('kills: 1\n' + log); }			}		} else if (input.match(/^kill.*/)) { var kills = log.match('kills: ') ? parseFloat((log.match(/kills: [0-9]+/)).join().replace('kills: ', )) + 1 : 0; $('#dropLog').val(log.replace(/kills: [0-9]+/, 'kills: ' + kills)); }		$('#dropLogEnter').val('').focus; $('#dropLog').val($('#dropLog').val.replace(/(\r|\n)(\r|\n)+/g, '$1')); });	$('#wikiCode').click(function { if ($('#dropLog').val.length != 0) { $('#dropLog').val($('#dropLog').val.replace(/^|: |(\r|\n)/g, '$1|').replace(/\|\|/g, '|').replace('kills|', 'kills=')); }	});	$('#default').click(function { $('#dropLog').val($('#dropLog').val.replace(/\|(([0-9]+)(\r|\n)?)\|?/g, ': $1').replace(/(\n|\r)\|/, '$1').replace('|kills=', 'kills: ')); }) })

//Closing JQuery import })//End closing JQuery import