x

MESSAGE     ARCHIVE    RSS     THEME   
MOLLY - FROM ENGLAND - LIVE IN DUBAI - SEVENTEEN
// ==UserScript== // @name XKit // @namespace http://userscripts.org/users/atesh // @description Extension framework for Tumblr. Useful additions and tweaks. // @include http://www.tumblr.com/* // @exclude http://www.tumblr.com/upload/image* // @version 0.5.7 // ==/UserScript== // Versioning information. var xframework_version_major = "5"; var xframework_version_minor = "7"; var xframework_version = xframework_version_major + "." + xframework_version_minor; var xframework_update_url = "http://userscripts.org/scripts/source/109272.user.js"; var xversion = xframework_version; // here for compatibility reasons. var xframework_in_reset_mode = false; var xframework_panic = false; var xframework_debug_mode = true; // Bootstrap code. var xbootstrap_code = GM_getValue("xkit_bootstrap_code", ""); // debug mode: var xlog_debugmode = GM_getValue("xkit_log_debug_mode", "true"); // Bootstrap download URLs. var xbootstrap_fetch_url_c = 0; var xbootstrap_fetch_urls = new Array(); xbootstrap_fetch_urls[0] = "http://www.studioxenix.com/xkit/bootstrap/bootstrap.1.2.js.php"; xbootstrap_fetch_urls[1] = "http://studioxenix.com/xkit/bootstrap/bootstrap.1.2.js.php"; xbootstrap_fetch_urls[2] = "http://www.puaga.com/xkit/bootstrap/bootstrap.1.2.js.php"; xbootstrap_fetch_urls[3] = "http://xkit.puaga.com/bootstrap/bootstrap.1.2.js.php"; var xbootstrap_page_url = window.location.href; var xbootstrap_global_name = new Array(); var xbootstrap_global_data = new Array(); var xbootstrap_globalf_name = new Array(); var xbootstrap_globalf_data = new Array(); var xbootstrap_internal_name = new Array(); var xbootstrap_internal_data = new Array(); var xkit_is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1; // Boot the XKit! try { xkit_init(); } catch(e) { if (document.location.href.indexOf("www.tumblr.com") !== -1) { xpanic("JS error: " + e.message, "xkit_usrptlandcode"); } else { xlog("Detected the following error: " + e.message, "xbootstrapinit"); } } function xkit_init() { // Framework initial startup section. if (xkit_is_chrome === true) { alert("XKit Error: Wrong browser!\n\nIt looks like you've installed a version of XKit intended for Firefox users!\n\nYou need to download XKit from xkit-extension.tumblr.com or www.studioxenix.com.\n\nPlease click on the Wrench button on top right of your browser, select Preferences, then Extensions, and remove XKit and re-download it from the links provided above."); GM_setValue("xkit_unsupported_browser","true"); return; } // Lets set the 'next generation' variable. GM_setValue("xkit_5","true"); // let's first check if we are in a 'special' page, such as log and reset. if (xframework_in_reset_mode === false) { if (xkit_special_pages() === true) { // we are! stop. xlog("XKit 'special' page. Stopping init.", "xkit_init"); return; } } // Check if XKit was disabled by code. if (GM_getValue("xkit_unsupported_browser","false") === "true") { xlog("XKit is disabled.", "xkit_init"); return; } // Let's first check if the bootstrap code is installed. xbootstrap_code = GM_getValue("xkit_bootstrap_code", ""); var start_up_text = "*** Welcome to XKit! ***"; start_up_text = start_up_text + "\n\tEdition: Userscript version"; start_up_text = start_up_text + "\n\tCopyright 2011-2012 STUDIOXENIX\n"; start_up_text = start_up_text + "\n\tFramework Version: " + xframework_version; if (xbootstrap_code === "") { start_up_text = start_up_text + "\n*** NO BOOTSTRAP CODE! ***"; } else { start_up_text = start_up_text + "\n\tBootstrap version: '" + xkit_package_information("xkit_bootstrap_code","version") + "'"; start_up_text = start_up_text + "\n\txkit_main version: '" + xkit_package_information("xkit_main","version") + "'"; } start_up_text = start_up_text + "\n\n\tOn Chrome: '" + xkit_is_chrome + "'"; start_up_text = start_up_text + "\n\tPlatform: '" + navigator.platform + "'"; start_up_text = start_up_text + "\n\tBrowser UA: '" + navigator.userAgent + "'"; start_up_text = start_up_text + "\n\n\tDebug Mode: '" + xframework_debug_mode + "'"; start_up_text = start_up_text + "\n\tWorking on: " + window.location.href; start_up_text = start_up_text + "\n\n\tLast Panic: '" + xget("xkit_framework_last_panic", "none") + "'"; xlog(start_up_text, "xkit_init"); if (xbootstrap_code === "" || xframework_in_reset_mode === true) { // It is not. xlog("Bootstrap code not found, installing.", "xkit_init"); // xkit_silent_reset(); xkit_bootstrap_download(); } else { // It is! // let's first check if the user is upgrading from 4.x. var xkit_main_package_version = xkit_package_information("xkit_main","version"); if (xkit_main_package_version === "1.0 REV B" || xkit_main_package_version === "1.1 REV B") { xkit_reset(true); } else { xkit_bootstrap_boot(); } } } function xkit_special_pages() { // checks if we are in a 'special' page. if (xframework_in_reset_mode === true) { return false; } var page_location = window.location.href; if (page_location.search("www.tumblr.com/xkit_clear_log") != -1) { // clear the log! GM_setValue("xkit_log", ""); alert("XKit diagnostics log cleared."); } if (page_location.search("www.tumblr.com/xkit_log") != -1) { // show the log! xkit_special_pages_remove_not_found(""); try { document.getElementById('l10n_title').innerHTML = 'XKit Diagnostics Log'; if (document.createTextNode){ var log_html = GM_getValue("xkit_log",""); log_html = log_html.replace(/\n/g,'
'); log_html = log_html.replace(/NaN/g,''); log_html = log_html.replace(/

/g,'

'); var err_div = create('

XKit Diagnostics Log:
To clean the log, go to www.tumblr.com/xkit_clear_log
'); document.getElementById("container").appendChild(err_div); } } catch(e) { alert("XKit Log: \n" + GM_getValue("xkit_log","Can't find log.")); } return true; } if (page_location.search("www.tumblr.com/xkit_reset") != -1) { // show the log! xkit_special_pages_remove_not_found("Please wait and check the message boxes."); if (confirm("Are you sure you want to reset XKit?")){ xkit_reset(true); } else { window.location.href = "http://www.tumblr.com/dashboard/"; } return true; } if (page_location.search("www.tumblr.com/xkit_reinstall_xprefs") != -1) { // show the log! xkit_special_pages_remove_not_found("One second..."); var remoteurl = "http://www.puaga.com/xkit/ext/fetch.php?fln=xkit_preferences"; remoteurl = remoteurl + "&rn2=" + Math.floor(Math.random()*669); remoteurl = remoteurl + "&rn3=" + Math.floor(Math.random()*69); remoteurl = remoteurl + "&rn4=" + Math.floor(Math.random()*9); GM_xmlhttpRequest({ method: "GET", url: remoteurl, onerror: function(response) { document.getElementById('l10n_title').innerHTML = 'Failed, retry later.'; return; }, onabort: function(response) { document.getElementById('l10n_title').innerHTML = 'Failed, retry later.'; return; }, onload: function(response) { document.getElementById('l10n_title').innerHTML = 'OK!'; GM_setValue("xkit_preferences", response.responseText); // window.location = "http://www.tumblr.com/dashboard/"; } }); return true; } } function xkit_special_pages_remove_not_found(msg) { // removes the "not found" text on 'special' pages. // otherwise, this confuses the users. try { // remove the stuff from page. var element = document.getElementById("l10n_sorry_1"); element.parentNode.removeChild(element); element = document.getElementById("l10n_email_button"); element.parentNode.removeChild(element); document.getElementById('l10n_title').innerHTML = 'XKit'; document.title = "XKit"; if (msg != undefined) { document.getElementById('l10n_sorry_2').innerHTML = msg; } else { element = document.getElementById("l10n_sorry_2"); element.parentNode.removeChild(element); } } catch(e) { // oh well at least we tried. return; } } function xkit_bootstrap_download_i(array_index) { try { // this download the bootstrap. var remoteurl = xbootstrap_fetch_urls[array_index]; xlog("Array index: " + array_index,"xkit_bootstrap_download_i"); xlog("Downloading bootstrap from: " + remoteurl,"xkit_bootstrap_download_i"); if (remoteurl.indexOf("?") != -1) { remoteurl = remoteurl + "&rn1=" + Math.floor(Math.random()*9669); } else { remoteurl = remoteurl + "?rn1=" + Math.floor(Math.random()*9669); } remoteurl = remoteurl + "&rn2=" + Math.floor(Math.random()*666); remoteurl = remoteurl + "&rn3=" + Math.floor(Math.random()*666); remoteurl = remoteurl + "&rn4=" + Math.floor(Math.random()*666); GM_xmlhttpRequest({ method: "GET", url: remoteurl, synchronous: true, onabort: function(response) { xkit_bootstrap_log("download failed, retrying...."); xkit_bootstrap_download(); return; }, onload: function(response) { if (response.responseText.indexOf("// Bootstrapper for XKit.") == -1) { // oops! download failed! retry. xlog("Download failed. Retrying, using another server.","xkit_bootstrap_download_i"); xkit_bootstrap_download(); return; } else { xlog("Download of bootstrap was successful.","xkit_bootstrap_download_i"); xlog("Booting new code.","xkit_bootstrap_download_i"); GM_setValue("xkit_bootstrap_code", response.responseText); xframework_in_reset_mode = false; xbootstrap_fetch_url_c = 0; xkit_init(); } } }); } catch(e) { alert("An error occurred while trying to download the bootstrap code:\n\n" + e.message); throw("Error 1031"); } } function xkit_bootstrap_download_i_chrome(array_index) { try { // this download the bootstrap. var remoteurl = xbootstrap_fetch_urls[array_index]; xlog("Array index: " + array_index,"xkit_bootstrap_download_i"); xlog("Downloading bootstrap from: " + remoteurl,"xkit_bootstrap_download_i"); if (remoteurl.indexOf("?") != -1) { remoteurl = remoteurl + "&rn1=" + Math.floor(Math.random()*9669); } else { remoteurl = remoteurl + "?rn1=" + Math.floor(Math.random()*9669); } document.title = "Downloading XKit Bootstap [Chrome Mode]"; remoteurl = remoteurl + "&rn2=" + Math.floor(Math.random()*666); remoteurl = remoteurl + "&rn3=" + Math.floor(Math.random()*666); remoteurl = remoteurl + "&rn4=" + Math.floor(Math.random()*666); if (typeof GM_xmlhttpRequest === 'undefined') { xkit_give_out_chrome_xml_error("502"); } GM_xmlhttpRequest({ method: "GET", url: remoteurl, synchronous: false, onload: function(response) { if (typeof response === 'undefined') { xkit_give_out_chrome_xml_error("504"); } try { if (response.responseText.indexOf("// Bootstrapper for XKit.") == -1) { // oops! download failed! retry. xlog("Download failed. Retrying, using another server.","xkit_bootstrap_download_i"); xkit_bootstrap_download(); return; } else { xlog("Download of bootstrap was successful.","xkit_bootstrap_download_i"); xlog("Booting new code.","xkit_bootstrap_download_i"); alert("(XKit Chrome Safe-Mode)\n\nXKit Bootstrap downloaded sucessfully.\nTrying to start the XKit Installer.\n\nServer ID: " + xbootstrap_fetch_url_c); GM_setValue("xkit_bootstrap_code", response.responseText); xframework_in_reset_mode = false; xbootstrap_fetch_url_c = 0; xkit_init(); } } catch(e) { xkit_give_out_chrome_xml_error("508"); } } }); } catch(e) { alert("An error occurred while trying to download the bootstrap code:\n\n" + e.message); throw("Error 1031"); } } function xkit_give_out_chrome_xml_error(error_id) { alert("XKit: \n\nYou are using a version of Google Chrome that does not support cross domain fetching, which is required for XKit to run.\n\nPlease update your browser or go to xkit-extension.tumblr.com to file a bug report or get more information about this issue. (Error Code: " + error_id + ")"); } function xkit_bootstrap_download() { // downloads the bootstrap code from studioxenix.com // or any other server specified on the array above. if (xbootstrap_fetch_url_c > xbootstrap_fetch_urls.length) { // we tried all the urls but could not download the // bootstrap code! shit. panic? xpanic("ERROR! Could not download the bootstrap code. Server down.", "xkit_bootstrap_download"); xlog("ERROR! Could not download the bootstrap code. Server down.", "xkit_bootstrap_download"); return; } // call the sub-function that will download the file. if (xkit_is_chrome === true) { xkit_bootstrap_download_i_chrome(xbootstrap_fetch_url_c); } else { xkit_bootstrap_download_i(xbootstrap_fetch_url_c); } xbootstrap_fetch_url_c++; } function xkit_package_boot(package_name, die_silently) { // "boots up" a package. // if "die_silently" is set to true, won't make a fuss about it. // returns true if ran successfully. try { // lets just run it. eval(GM_getValue(package_name)); return true; } catch(e) { xlog("Unable to run package '" + package_name + "': " + e.message, "xkit_package_boot(" + package_name + ")"); if (die_silently === undefined) { xpanic("Unable to run package '" + package_name + "'! XKit will disable this extension now, and it it recommended that you file a bug report about it, and perform a reset to XKit to avoid more problems.\n\n(Javascript Error: " + e.message + ")", "xkit_package_boot"); } return false; } } function xkit_show_log_page() { window.location.href = 'http://www.tumblr.com/xkit_log'; } function xkit_bootstrap_boot() { // "boots up" the bootstrap code. //if(unsafeWindow.top != unsafeWindow.self) { // return; //} try { // lets just run it. // eval(xbootstrap_code); eval(GM_getValue("xkit_bootstrap_code")); return true; } catch(e) { // ooops, something bad has happened? // let's just re-download the bootstrap? xlog("ERROR! Unable to boot Bootstrap code..", "xkit_bootstrap_boot"); xlog(" *** Javascript error: '" + e.message + "'", "xkit_bootstrap_boot"); xpanic("Unable to run Bootstrap code. XKit will now reset to its default settings so you can continue using it.\n\n(Javascript Error: " + e.message + ")", "xkit_bootstrap_boot"); xkit_reset(); return false; } } function xkit_silent_reset() { try { GM_deleteValue("xkit_bootstrap_code"); GM_deleteValue("xkit_main"); GM_deleteValue("xkit_installer"); GM_deleteValue("xkit_installed_extensions"); GM_deleteValue("xm_xkit_preferences_on"); GM_deleteValue("xkit_installation_complete"); GM_deleteValue("xkit_unsupported_browser"); var mlist = GM_listValues(); var i = 0; for (i=0; i 20240) { prev_log = ""; } prev_log = prev_log + + "
  • " + originator + ":

    " + logtext + "

  • "; GM_setValue("xkit_log", prev_log); if (xframework_debug_mode === true) { console.log(originator + ":\n * " + logtext); } } catch(e) { // sth bad happened but meh. return; } } function xpanic(msg, originator) { // used to halt the operation of the extension. // only used when something catastrophic has happened. try { if (xframework_panic === false) { var panic_msg = "XKIT PANIC!\nXKit stopped working.\n\nSomething catastrophic has happened.\nExtension-wise, at least.\n\nPlease consult the XKit FAQ on xkit-extension.tumblr.com, or go to www.tumblr.com/xkit_reset to reset and re-install XKit.\n\nMessage:\n" + msg + "\n\nOriginator:\n'" + originator + "'"; xlog(panic_msg, "xpanic"); alert(panic_msg); xframework_panic = true; xset("xkit_framework_last_panic", panic_msg); } } catch(e) { alert("XKIT PANIC!\nThe following error occurred while trying to run the framework:\n\n" + e.message); } } function xkit_package_information(gmsavealias, info_needed) { var tempdata = GM_getValue(gmsavealias, ""); info_needed = info_needed.toUpperCase(); var inf_string = "/* " + info_needed + " "; var str_start = tempdata.indexOf(inf_string); if (str_start === -1) { return ""; } var str_end = tempdata.indexOf("**/", str_start); if (str_end === -1) { return ""; } return tempdata.substring(str_start + (inf_string.length), str_end - 1); } function xkit_bootstrap_attach_source(gmsavealias) { var source = GM_getValue(gmsavealias, ""); if (xkit_bootstrap_installed(gmsavealias) === false || source === "") { return ""; } var headID = document.getElementsByTagName("head")[0]; var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = source; headID.appendChild(newScript); } function xkit_bootstrap_installed(gmsavealias) { if (gmsavealias === "") { return false; } else { return true; } } function xglobalf_check(variablename) { var i = 0; for (i = 0; i" + data + ""); } function xkit_bootstrap_load_nosafeguard(scriptalias) { // same as xkit_bootstrap_boot, but when failed, doesn't shut down // the whole extension. xlog("xkit_bootstrap_load_nosafeguard: " + scriptalias, "xkit_bootstrap_load_nosafeguard"); var xload_code = GM_getValue(scriptalias, ""); if (xload_code === "") { xkit_bootstrap_log("xkit_bootstrap_load_nosafeguard: " + scriptalias + " > ERROR! Empty!"); return; } try{ eval(xload_code); } catch(e){ // nothing! xkit_bootstrap_log(" **** xkit_bootstrap_load_nosafeguard: " + scriptalias + " > ERROR! -> " + e.message); } finally{ return; } xkit_bootstrap_log("xkit_bootstrap_load_nosafeguard: " + scriptalias + " > DONE!"); } function xset(gmalias, data) { // chrome fails unless we do this. GM_deleteValue(gmalias); GM_setValue(gmalias, data); } function xappend(gmalias, data) { // chrome fails unless we do this. var old_data = GM_getValue(gmalias, ""); var new_data = old_data + data; GM_deleteValue(gmalias); GM_setValue(gmalias, new_data); } function xget(gmalias, defaultdata) { // chrome fails unless we do this. return GM_getValue(gmalias, defaultdata); } function create(htmlStr) { var frag = document.createDocumentFragment(), temp = document.createElement('div'); temp.innerHTML = htmlStr; while (temp.firstChild) { frag.appendChild(temp.firstChild); } return frag; }