Ventero's Chat-scripts Framework *OLD*

Required by all of Ventero's Kongregate scripts

  1. // ==UserScript==
  2. // @name Ventero's Chat-scripts Framework *OLD*
  3. // @namespace tag://kongregate
  4. // @description Required by all of Ventero's Kongregate scripts
  5. // @include http://www.kongregate.com/*
  6. // @author Ventero
  7. // @version 1.9
  8. // @date 05.04.2013
  9. // require http://kong.ventero.de/updates/54245.js
  10. // @grant unsafeWindow
  11. // @license MIT license
  12. // ==/UserScript==
  13.  
  14. // Written by Ventero (http://www.kongregate.com/accounts/Ventero) 07/22/09
  15. // Copyright (c) 2009-2012 Ventero, licensed under MIT/X11 license
  16. // http://www.opensource.org/licenses/mit-license.php
  17. var dom = (typeof unsafeWindow === "undefined"?window:unsafeWindow);
  18. var ready = false;
  19.  
  20. // cross window communication
  21. window.addEventListener("message", function onMessage(e) {
  22. if(e.data != "__scripts_ready" || e.origin != location.origin) return;
  23.  
  24. ready = true;
  25. window.removeEventListener("message", onMessage);
  26. }, false);
  27.  
  28. injectScript(function bootstrap(dom){
  29. var target = ("holodeck" in dom ? "holodeck:ready" : "dom:javascript_loaded");
  30. document.addEventListener("dataavailable", function listener(e) {
  31. if(e.eventName != target) return;
  32.  
  33. ready = true;
  34. window.postMessage("__scripts_ready", location.origin);
  35. document.removeEventListener("dataavailable", listener);
  36. }, false);
  37. }, 0, true);
  38.  
  39. function injectScript(fn, to, force){
  40. if(!ready && !force) {
  41. setTimeout(function(){injectScript(fn, to)}, 100);
  42. return;
  43. }
  44. try{
  45. var inject;
  46. if(force ||
  47. /Chrome/i.test(navigator.appVersion) ||
  48. typeof unsafeWindow === "undefined"){
  49. var script = document.createElement("script");
  50. var source = fn.toString();
  51. if(source[source.length - 1] == ";"){
  52. source = source.substring(0, source.length - 1);
  53. }
  54.  
  55. script.type = "text/javascript";
  56. script.textContent = "//<![CDATA[\n" +
  57. "(" + source + ")(window);\n" +
  58. "//]]>";
  59.  
  60. setTimeout(function(){document.body.appendChild(script)}, to);
  61. }else{
  62. setTimeout(function(){fn(unsafeWindow);}, to);
  63. }
  64.  
  65. }catch(e){console.log("Framework script: " + e)};
  66. }
  67. dom.injectScript = injectScript;
  68.  
  69. function init_framework(){
  70. if(dom.holodeck){
  71. dom.CDprototype = dom.ChatDialogue.prototype;
  72. dom.CWprototype = dom.ChatWindow.prototoype;
  73. dom.CRprototype = dom.ChatRoom.prototype;
  74. dom.Holoprototype = dom.Holodeck.prototype;
  75. }
  76.  
  77. addScript = document.createElement("script");
  78. addScript.innerHTML = "function ajax(a, b){new Ajax.Request(a,b)};\n";
  79. addScript.innerHTML+= "function wrap(a, b){return a.wrap(b)};\n";
  80. document.body.appendChild(addScript);
  81. }
  82.  
  83. if(window.opera){
  84. if(window.localStorage){
  85. window.GM_setValue = function(a, b){
  86. localStorage.setItem(a, b);
  87. }
  88. window.GM_getValue = function(a, b){
  89. var ret = localStorage.getItem(a);
  90. return (ret == null?b:ret)
  91. }
  92. window.GM_deleteValue = function(a){
  93. localStorage.removeItem(a);
  94. }
  95. } else {
  96. window.GM_setValue = function(){};
  97. window.GM_getValue = function(){};
  98. window.GM_deleteValue = function(){};
  99. }
  100. }else if(/Chrome/i.test(navigator.appVersion) || typeof unsafeWindow === "undefined"){
  101. var s = document.createElement("script");
  102. s.id = "injectScriptDiv";
  103. s.innerHTML = "dom = window;\n";
  104. s.innerHTML+= "if(typeof GM_setValue === 'undefined'){\n";
  105. s.innerHTML+= " window.GM_setValue = function(a,b){localStorage.setItem(a,b)}\n";
  106. s.innerHTML+= " window.GM_getValue = function(a,b){var r=localStorage.getItem(a);return (r==null?b:r)}\n";
  107. s.innerHTML+= " window.GM_deleteValue = function(a){localStorage.removeItem(a)}\n";
  108. s.innerHTML+= "}";
  109. s.onclick = function(){return dom.injectScript};
  110. document.body.appendChild(s);
  111. }
  112.  
  113. injectScript(init_framework, 0);