// ==UserScript== // @name Nein // @namespace Gallery // @include *.bronies.de/showthread.php?* // @author Rapti // @version 1.1 // @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js // ==/UserScript== this.$ = this.jQuery = jQuery.noConflict(true); var chars = { "і": "i", "í": "i", "ȋ": "i", "ä": "a", "ā": "a", "ặ": "a" }; var chaas = { "b": "i", "c": "i", "s": "a", "g": "a", "h": "a" }; var answer = function () { wikipedia("Baum"); var text = textarea.value; var posts = splitPosts("[/quote]", text, 0); text = ""; for (var i in posts) { var post = posts[i]; if (post.replace(" ", "").split("\n").join("") == "") { continue; } var bracket1 = post.indexOf("[quote"); var bracket2 = post.indexOf("]"); var quoteHeader = post.substring(bracket1, bracket2 + 1); if (post.indexOf("?") == post.lastIndexOf("?")) { if (nein) text += post + "[/quote]Nein.\n"; else { var reply = prompt(post.replace(quoteHeader, "").replace("/n"), ""); if (reply == null) return; text += post + "[/quote]" + reply + "\n"; } } else { var questions = splitPosts("\n", post, -1); while (questions.length > 0) { var question = questions[0]; if (splitPosts("?", question, 0).length > 1) { if (nein) { var withoutSpaces = question; if (withoutSpaces.indexOf(" ") != -1) withoutSpaces = withoutSpaces.replace(/ /g, ""); for (var val in chars) { withoutSpaces = withoutSpaces.split(val).join(chars[val]); } if (withoutSpaces.indexOf("Wassind") == 0) text += question + "[/quote]Weiß ich nicht.\n" + quoteHeader; else if (withoutSpaces.indexOf("WashaltstDuvon") == 0) text += question + "[/quote]Nichts.\n" + quoteHeader; else if (withoutSpaces.indexOf("KannstDu") == 0) text += question + "[/quote]Ja.\n" + quoteHeader; else if (question.indexOf(" odel ") != -1) text += question + "[/quote]Ist mir egal.\n" + quoteHeader; else text += question + "[/quote]Nein.\n" + quoteHeader; } else { var reply = prompt(question); if (reply == null) return; text += question + "[/quote]" + reply + "\n" + quoteHeader; } } else { if (question != "") text += question + "\n"; } questions.splice(0, 1); } text = (text + "[/quote]").replace(quoteHeader + "[/quote]", ""); } } textarea.value = text; textarea.focus(); } function splitPosts(search, string, quote) { var split = string.split(""); var out = []; var buffer = ""; var i = 0; while (split.length > i) { var char = split[i]; if (char == "[") { if (string.substring(i, i + 6) == "[quote") { quote++; } else if (string.substring(i, i + 8) == "[/quote]") { quote--; } } if (char == search.substring(0, 1) && quote < 1) { if (string.substring(i, i + search.length) == search) { out.push(buffer); buffer = ""; split.splice(0, i + search.length); string = string.substring(i + search.length); i = 0; continue; } } buffer += char; i++; } out.push(buffer); return out; } var replywithno = function () { nein = true; answer(); nein = false; } var wikipedia = function (s) { /* alert("Looking up " + s); var url = "http://de.wikipedia.org/w/api.php?action=opensearch&format=xml&limit=1&search=" + s; var jqxhr = $.ajax("http://merrx.bestpony.de/smiley/smiley.php") .done(function () { alert("success"); }) .fail(function () { alert("error"); }) .always(function () { alert("complete"); });*/ function start() { var zuFragen = ["Baum", "Hello", "World", "of", "Minecraft"]; var Antworten = []; console.log(zuFragen.length); function fragWiki(i) { console.log(zuFragen[i]); var link = "http://de.wikipedia.org/w/api.php?action=opensearch&format=xml&limit=1&search=" + zuFragen[i]; GM_xmlhttpRequest({ method: 'GET', url: link, onload: function (response) { var responseHTML = document.implementation.createHTMLDocument("example"); responseHTML.documentElement.innerHTML = response.responseText; Antworten.push($j(responseHTML).find("Description").html()); if (zuFragen.length != i + 1) { fragWiki(i + 1); } else fertig(Antworten); } }); } if (zuFragen.length > 0) fragWiki(0); function fertig(ant) { console.log(ant); } } } var textarea = document.getElementById("message"); var nein = false; var bar = document.getElementById("quick_reply_submit").parentElement var button = document.createElement("input"); button.setAttribute("value", "Beantworten"); button.setAttribute("class", "button"); button.setAttribute("type", "button"); button.onclick = answer; bar.appendChild(document.createTextNode(" ")); bar.appendChild(button); button = document.createElement("input"); button.setAttribute("value", "Nein"); button.setAttribute("class", "button"); button.setAttribute("type", "button"); button.onclick = replywithno; bar.appendChild(document.createTextNode(" ")); bar.appendChild(button);