// ==UserScript==
// @name KoC Merlin Token Domain Selector FRANCAIS
// @icon https://kabam1-a.akamaihd.net/kingdomsofcamelot/fb/e2/src/img/feeds/merlin_magical_token.jpg
// @namespace KoCDomSel
// @description This script will automatically select your domain when accepting Merlins Tokens from Facebook!
// @include *kingdomsofcamelot.com/fb/e2/src/claimVictoryToken_src.php*
// @include *kingdomsofcamelot.com/fb/e2/src/merlinShare_src.php*
// @include *kingdomsofcamelot.com/fb/e2/src/acceptToken_src.php*
// @include *kingdomsofcamelot.com/fb/e2/src/helpFriend_src.php*
// @include *.kingdomsofcamelot.com/*main_src.php*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_listValues
// @grant GM_log
// @grant GM_xmlhttpRequest
// @grant unsafeWindow
// @version 0.13a
// @license http://creativecommons.org/licenses/by-nc-sa/3.0/
// @downloadURL none
// ==/UserScript==
//
// May 2014 Barbarossa69 (www.facebook.com/barbarossa69)
// Script adapted from "Auto Accept Kingdoms of Camelot Gifts" by Thomas Chapin
// https://koc-battle-console.googlecode.com/svn/trunk/KoCDomainSelector.user.js
//
// 22/02/15 - BeWorld : Update to delete filter app
// 24/02/15 Barbarossa : Update code
var Version = '0.13a';
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, '');
}
String.prototype.StripQuotes = function () {
return this.replace(/"/g, '');
};
if (!this.JSON2) {
JSON2 = {};
}
(function () {
function f(n) {
return n < 10 ? '0' + n : n;
}
if (typeof Date.prototype.toJSON !== 'function') {
Date.prototype.toJSON = function (key) {
return this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z';
};
String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function (key) {
return this.valueOf();
};
}
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
gap,
indent,
meta = {
'\b' : '\\b',
'\t' : '\\t',
'\n' : '\\n',
'\f' : '\\f',
'\r' : '\\r',
'"' : '\\"',
'\\' : '\\\\'
},
rep;
function quote(string) {
escapable.lastIndex = 0;
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
var c = meta[a];
return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
}) + '"' : '"' + string + '"';
}
function str(key, holder) {
var i,
k,
v,
length,
mind = gap,
partial,
value = holder[key];
if (value && typeof value === 'object' && typeof value.toJSON === 'function') {
value = value.toJSON(key);
}
if (typeof rep === 'function') {
value = rep.call(holder, key, value);
}
switch (typeof value) {
case 'string':
return quote(value);
case 'number':
return isFinite(value) ? String(value) : 'null';
case 'boolean':
case 'null':
return String(value);
case 'object':
if (!value) {
return 'null';
}
gap += indent;
partial = [];
if (Object.prototype.toString.apply(value) === '[object Array]') {
length = value.length;
for (i = 0; i < length; i += 1) {
partial[i] = str(i, value) || 'null';
}
v = partial.length === 0 ? '[]' : gap ? '[\n' + gap +
partial.join(',\n' + gap) + '\n' +
mind + ']' : '[' + partial.join(',') + ']';
gap = mind;
return v;
}
if (rep && typeof rep === 'object') {
length = rep.length;
for (i = 0; i < length; i += 1) {
k = rep[i];
if (typeof k === 'string') {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
}
}
}
} else {
for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
}
}
}
}
v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
mind + '}' : '{' + partial.join(',') + '}';
gap = mind;
return v;
}
}
if (typeof JSON2.stringify !== 'function') {
JSON2.stringify = function (value, replacer, space) {
var i;
gap = '';
indent = '';
if (typeof space === 'number') {
for (i = 0; i < space; i += 1) {
indent += ' ';
}
} else if (typeof space === 'string') {
indent = space;
}
rep = replacer;
if (replacer && typeof replacer !== 'function' && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
throw new Error('JSON.stringify');
}
return str('', {
'' : value
});
};
}
if (typeof JSON2.parse !== 'function') {
JSON2.parse = function (text, reviver) {
var j;
function walk(holder, key) {
var k,
v,
value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
} else {
delete value[k];
}
}
}
}
return reviver.call(holder, key, value);
}
cx.lastIndex = 0;
if (cx.test(text)) {
text = text.replace(cx, function (a) {
return '\\u' +
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
});
}
if (text) {
if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
j = eval('(' + text + ')');
return typeof reviver === 'function' ? walk({
'' : j
}, '') : j;
}
}
throw new SyntaxError('JSON.parse');
};
}
})();
if (!this.GM_log) {
GM_log = function (m) {
console.log(m);
}
GM_registerMenuCommand = function (text, f) {}
}
if (!this.unsafeWindow) {
//~~~ need helper to return values?
unsafeWindow = {};
}
function AddScript(script) {
var a = document.createElement('script');
a.innerHTML = script;
document.getElementsByTagName('head')[0].appendChild(a);
return;
}
function inspect(obj, maxLevels, level) {
var str = '',
type,
msg;
// Start Input Validations
// Don't touch, we start iterating at level zero
if (level == null)
level = 0;
// At least you want to show the first level
if (maxLevels == null)
maxLevels = 1;
if (maxLevels < 1)
return 'Error: Levels number must be > 0';
// We start with a non null object
if (obj == null)
return 'Error: Object NULL';
// End Input Validations
// Each Iteration must be indented
str += '
';
// Start iterations for all objects in obj
for (property in obj) {
try {
// Show "property" and "type property"
type = typeof(obj[property]);
str += '- (' + type + ') ' + property +
((obj[property] == null) ? (': null') : (': ' + obj[property])) + '
';
// We keep iterating if this property is an Object, non null
// and we are inside the required number of levels
if ((type == 'object') && (obj[property] != null) && (level + 1 < maxLevels))
str += inspect(obj[property], maxLevels, level + 1);
} catch (err) {
// Is there some properties in obj we can't access? Print it red.
if (typeof(err) == 'string')
msg = err;
else if (err.message)
msg = err.message;
else if (err.description)
msg = err.description;
else
msg = 'Unknown';
str += '- (Error) ' + property + ': ' + msg + '
';
}
}
// Close indent
str += '
';
return str;
}
var nHtml = {
FindByXPath : function (obj, xpath, nodetype) {
if (!nodetype) {
nodetype = XPathResult.FIRST_ORDERED_NODE_TYPE;
}
try {
var q = document.evaluate(xpath, obj, null, nodetype, null);
} catch (e) {
GM_log('bad xpath:' + xpath);
}
if (nodetype == XPathResult.FIRST_ORDERED_NODE_TYPE) {
if (q && q.singleNodeValue) {
return q.singleNodeValue;
}
} else {
if (q) {
return q;
}
}
return null;
},
ClickWin : function (win, obj, evtName) {
var evt = win.document.createEvent("MouseEvents");
evt.initMouseEvent(evtName, true, true, win,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
return !obj.dispatchEvent(evt);
},
Click : function (obj) {
return this.ClickWin(window, obj, 'click');
},
ClickTimeout : function (obj, millisec) {
window.setTimeout(function () {
return nHtml.ClickWin(window, obj, 'click');
}, millisec + Math.floor(Math.random() * 500));
},
SetSelect : function (obj, v) {
for (var o = 0; o < obj.options.length; o++) {
if (v == obj.options[o].value) {
obj.options[o].selected = true;
return true;
}
}
return false;
}
};
function ById(id) {
return document.getElementById(id);
}
function ByName(name) {
return document.getElementsByName(name);
}
function AddText(box1, txt) {
var txtObj;
box1.appendChild(txtObj = document.createTextNode(txt));
return txtObj;
}
function AddHtml(box1, txt) {
var txtObj;
var sp = document.createElement('span');
sp.innerHTML = txt;
box1.appendChild(sp);
return txtObj;
}
function getServerId() { // domain for tokens may be passed in URL as &token_s parameter...
var myServerId = KOCAutoAcceptGifts.options.UserDomain;
var squery = /[\?,\&]token_s=\d+/;
var dquery = /\d+/;
var Sresult = dquery.exec(squery.exec(document.location.search));
if (Sresult)
myServerId = Sresult;
return myServerId;
}
function getBadServerId() {
var myServerId = KOCAutoAcceptGifts.options.UserDomain;
var squery = /[\?,\&]s=\d+/;
var dquery = /\d+/;
var Sresult = dquery.exec(squery.exec(document.location.search));
if (Sresult)
myServerId = Sresult;
return myServerId;
}
function createButton(label) {
var a = document.createElement('a');
a.className = 'button20';
a.innerHTML = '' + label + '';
return a;
}
function AddMainTabLink(text, eventListener, mouseListener) {
var a = createButton (text);
a.className='tab';
a.title='Have you collected your Merlins Tokens yet today?';
var tabs=document.getElementById('main_engagement_tabs');
if(!tabs) {
tabs=document.getElementById('topnav_msg');
if (tabs)
tabs=tabs.parentNode;
}
if (tabs) {
var e = tabs.parentNode;
var gmTabs = null;
for (var i=0; i