Advertisement
Degritone

BBS ReCaptcha Fix (Script Breaking)

Apr 13th, 2024
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         BBS Captcha Fix iFrame
  3. // @version      1.0
  4. // @description  Fix the BBS's Recaptcha with an iframe, which breaks most other scripts
  5. // @author       Degritone
  6. // @match        *://dollars-bbs.org/*
  7. // @grant        none
  8. // @run-at       document-end
  9. // ==/UserScript==
  10.  
  11.  
  12. function replaceHTML(){
  13.   let html = document.getElementsByTagName("html")[0].outerHTML
  14.     .replace(`var self=`,`var nameWithoutCollision = `)
  15.     .replace(`<script type="text/javascript" src="/random/kareha.js"></script>`,karehaUpdated)
  16.     .replace(`<body class="mainpage">`,"")
  17.     .replace(`</head>`,"")
  18.     .replace("<head>",`<body class="mainpage">`)
  19.  
  20.   let iframe = document.createElement("iframe");
  21.   iframe.style.cssText = `
  22.     position:fixed;
  23.     left:0px;
  24.     right:0px;
  25.     top:0px;
  26.     bottom:0px;
  27.     border:0px;
  28.     width:100%;
  29.     height:100%;
  30.   `;
  31.  
  32.   document.body.innerHTML = "";
  33.   document.body.appendChild(iframe);
  34.  
  35.   iframe.contentWindow.document.open();
  36.   iframe.contentWindow.document.write("<!doctype html>"+html);
  37.   iframe.contentWindow.document.close();
  38. }
  39.  
  40. let karehaUpdated = `<script>function require_script_version(v)
  41. {
  42.     if(v!="3.a") alert("");
  43. }
  44.  
  45.  
  46.  
  47. function show(id)
  48. {
  49.     var style=document.getElementById(id).style;
  50.     if(style.display) style.display="";
  51.     else style.display="none";
  52. }
  53.  
  54. function insert(text,thread)
  55. {
  56.     var textarea=document.getElementById("postform"+thread).comment;
  57.     if(textarea)
  58.     {
  59.         if(textarea.createTextRange && textarea.caretPos) // IE
  60.         {
  61.             var caretPos=textarea.caretPos;
  62.             caretPos.text=caretPos.text.charAt(caretPos.text.length-1)==" "?text+" ":text;
  63.         }
  64.         else if(textarea.setSelectionRange) // Firefox
  65.         {
  66.             var start=textarea.selectionStart;
  67.             var end=textarea.selectionEnd;
  68.             textarea.value=textarea.value.substr(0,start)+text+textarea.value.substr(end);
  69.             textarea.setSelectionRange(start+text.length,start+text.length);
  70.         }
  71.         else
  72.         {
  73.             textarea.value+=text+" ";
  74.         }
  75.         textarea.focus();
  76.     }
  77. }
  78.  
  79. function w_insert(text,link)
  80. {
  81.     if(document.body.className=="mainpage") document.location=link+"#i"+text;
  82.     else insert(text,"");
  83. }
  84.  
  85. function size_field(id,rows) { document.getElementById(id).comment.setAttribute("rows",rows); }
  86.  
  87. function submit_form(btn)
  88. {
  89.     btn.disabled = true;
  90.     btn.value = "Please wait...";
  91.     btn.form.submit();
  92. }
  93.  
  94. function delete_post(thread,post,file)
  95. {
  96.     if(confirm("Are you sure you want to delete reply "+post+"?"))
  97.     {
  98.         var fileonly=false;
  99.         var script=document.forms[0].action;
  100.         var password=document.forms[0].password.value;
  101.  
  102.         if(file) fileonly=confirm("Leave the reply text and delete the only file?");
  103.  
  104.         document.location=script
  105.         +"?task=delete"
  106.         +"&delete="+thread+","+post
  107.         +"&password="+password
  108.         +"&fileonly="+(fileonly?"1":"0");
  109.     }
  110. }
  111.  
  112. function preview_post(formid,thread)
  113. {
  114.     var form=document.getElementById(formid);
  115.     var preview=document.getElementById("preview"+thread);
  116.  
  117.     if(!form||!preview) return;
  118.  
  119.     preview.style.display="";
  120.     preview.innerHTML="<em>Loading...</em>";
  121.  
  122.     var text;
  123.     text="task=preview";
  124.     text+="&comment="+encodeURIComponent(form.comment.value);
  125.     text+="&markup="+encodeURIComponent(form.markup.value);
  126.     if(thread) text+="&thread="+thread;
  127.  
  128.     var xmlhttp=get_xmlhttp();
  129.     xmlhttp.open("POST",nameWithoutCollision);
  130.     xmlhttp.onreadystatechange=function() {
  131.         if(xmlhttp.readyState==4) preview.innerHTML=xmlhttp.responseText;
  132.     }
  133.     if(is_ie()||xmlhttp.setRequestHeader) xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  134.     xmlhttp.send(text);
  135. }
  136.  
  137. function get_xmlhttp()
  138. {
  139.     var xmlhttp;
  140.     try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
  141.     catch(e1)
  142.     {
  143.         try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
  144.         catch(e1) { xmlhttp=null; }
  145.     }
  146.  
  147.     if(!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
  148.  
  149.     return(xmlhttp);
  150. }
  151.  
  152. function is_ie()
  153. {
  154.     return(document.all&&!document.opera);
  155. }
  156.  
  157.  
  158.  
  159. function set_new_inputs(id)
  160. {
  161.     var el=document.getElementById(id);
  162.  
  163.     if(!el||!el.link) return;
  164.  
  165.     if(!el.field_a.value) el.field_a.value=get_cookie("name");
  166.     if(!el.password.value) el.password.value=get_password("password");
  167.     if(el.markup&&!el.comment.value) el.markup.value=get_cookie("markup");
  168.     select_markup(el.markup);
  169. }
  170.  
  171. function set_delpass(id)
  172. {
  173.     with(document.getElementById(id)) password.value=get_cookie("password");
  174. }
  175.  
  176. function make_password()
  177. {
  178.     var chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  179.     var pass='';
  180.  
  181.     for(var i=0;i<8;i++)
  182.     {
  183.         var rnd=Math.floor(Math.random()*chars.length);
  184.         pass+=chars.substring(rnd,rnd+1);
  185.     }
  186.  
  187.     return(pass);
  188. }
  189.  
  190. function get_password(name)
  191. {
  192.     var pass=get_cookie(name);
  193.     if(pass) return pass;
  194.     return make_password();
  195. }
  196.  
  197. function select_markup(sel)
  198. {
  199.     if(!window.markup_descriptions) return;
  200.  
  201.     var el=sel;
  202.     while(el=el.nextSibling) if(el.nodeName.toLowerCase()=="small") break;
  203.  
  204.     if(el) el.innerHTML=markup_descriptions[sel.value];
  205. }
  206.  
  207.  
  208.  
  209. function get_cookie(name)
  210. {
  211.     with(document.cookie)
  212.     {
  213.         var regexp=new RegExp("(^|;\\s+)"+name+"=(.*?)(;|$)");
  214.         var hit=regexp.exec(document.cookie);
  215.         if(hit&&hit.length>2) return unescape(hit[2]);
  216.         else return '';
  217.     }
  218. };
  219.  
  220. function set_cookie(name,value,days)
  221. {
  222.     if(days)
  223.     {
  224.         var date=new Date();
  225.         date.setTime(date.getTime()+(days*24*60*60*1000));
  226.         var expires="; expires="+date.toGMTString();
  227.     }
  228.     else expires="";
  229.     document.cookie=name+"="+value+expires+"; path=/";
  230. }
  231.  
  232. function set_stylesheet(styletitle)
  233. {
  234.     var links=document.getElementsByTagName("link");
  235.     var found=false;
  236.     for(var i=0;i<links.length;i++)
  237.     {
  238.         var rel=links[i].getAttribute("rel");
  239.         var title=links[i].getAttribute("title");
  240.         if(rel.indexOf("style")!=-1&&title)
  241.         {
  242.             links[i].disabled=true; // IE needs this to work. IE needs to die.
  243.             if(styletitle==title) { links[i].disabled=false; found=true; }
  244.         }
  245.     }
  246.     if(!found) set_preferred_stylesheet();
  247. }
  248.  
  249. function set_preferred_stylesheet()
  250. {
  251.     var links=document.getElementsByTagName("link");
  252.     for(var i=0;i<links.length;i++)
  253.     {
  254.         var rel=links[i].getAttribute("rel");
  255.         var title=links[i].getAttribute("title");
  256.         if(rel.indexOf("style")!=-1&&title) links[i].disabled=(rel.indexOf("alt")!=-1);
  257.     }
  258. }
  259.  
  260. function get_active_stylesheet()
  261. {
  262.     var links=document.getElementsByTagName("link");
  263.     for(var i=0;i<links.length;i++)
  264.     {
  265.         var rel=links[i].getAttribute("rel");
  266.         var title=links[i].getAttribute("title");
  267.         if(rel.indexOf("style")!=-1&&title&&!links[i].disabled) return title;
  268.     }
  269. }
  270.  
  271. function get_preferred_stylesheet()
  272. {
  273.     var links=document.getElementsByTagName("link");
  274.     for(var i=0;i<links.length;i++)
  275.     {
  276.         var rel=links[i].getAttribute("rel");
  277.         var title=links[i].getAttribute("title");
  278.         if(rel.indexOf("style")!=-1&&rel.indexOf("alt")==-1&&title) return title;
  279.     }
  280.     return null;
  281. }
  282.  
  283.  
  284.  
  285. window.onunload=function(e)
  286. {
  287.     if(style_cookie)
  288.     {
  289.         var title=get_active_stylesheet();
  290.         set_cookie(style_cookie,title,365);
  291.     }
  292. }
  293.  
  294. window.onload=function(e)
  295. {
  296.     var inputs = document.getElementsByTagName("input");
  297.   for (var i = 0; i < inputs.length; i++) {
  298.     if (inputs[i].type.toLowerCase() === "submit") {
  299.       inputs[i].disabled = false;
  300.     }
  301.   }
  302.     if(match=/#i(.+)/.exec(document.location.toString()))
  303.     if(!document.getElementById("postform").comment.value)
  304.     insert(unescape(match[1]),"");
  305. }
  306.  
  307. if(style_cookie)
  308. {
  309.     var cookie=get_cookie(style_cookie);
  310.     var title=cookie?cookie:get_preferred_stylesheet();
  311.     set_stylesheet(title);
  312. }
  313.  
  314. var captcha_key=make_password();</script>`
  315.  
  316. replaceHTML();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement