// ==UserScript== // @name [s4s] interface // @namespace s4s4s4s4s4s4s4s4s4s // @include https://boards.4chan.org/s4s/thread/* // @include http://boards.4chan.org/s4s/thread/* // @version 1.02 // @grant none // @author le fun css man AKA Doctor Worse Than Hitler // @email doctorworsethanhitler@gmail.com // @description Lets you view the greenposts. // @downloadURL none // ==/UserScript== // basic post html ///////////////////////////////////////////////////////////////////// //////// WANNA SET SOME STUFF UP HERE? GO FOR IT BBY! /////////////// //////// IT IS THE CONFIGURATION SPOTS WOW /////////////// var TEXT_COLOR = 'inherit'; // any css option for color is fine, eg #000, #000000, red, etc ///////////////////////////////////////////////////////////////////// // (more to come for above) var baseHTML = '
>>
&USERNAME& &DATE& '; var noHTML = 'No.&AFTER_NO&-&ID&'; var baseHTML2 = '
&TEXT&
'; var url = "https://funposting.online/interface/"; // ripped from https://www.elated.com/articles/working-with-dates/ -- is there not a better way to do this? who cares. var day_names = new Array(); day_names[day_names.length] = "Sun"; day_names[day_names.length] = "Mon"; day_names[day_names.length] = "Tue"; day_names[day_names.length] = "Wed"; day_names[day_names.length] = "Thu"; day_names[day_names.length] = "Fri"; day_names[day_names.length] = "Sat"; //shamelessly ripped from https://stackoverflow.com/questions/247483/http-get-request-in-javascript var HttpClient = function() { this.get = function(aUrl, aCallback) { var anHttpRequest = new XMLHttpRequest(); anHttpRequest.onreadystatechange = function() { if (anHttpRequest.readyState == 4 && anHttpRequest.status == 200) aCallback(anHttpRequest.responseText); } anHttpRequest.open("GET", aUrl, true); anHttpRequest.send(null); } } // add a post to the proper position in the thread function addPost(aPost) { console.log(aPost) var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };; var posthtml = baseHTML; if(aPost["options"] == "numberless") { posthtml += baseHTML2; posthtml = posthtml.replace(/\&AFTER_NO\&/g, "XXXXXX"); } else { posthtml += noHTML; posthtml += baseHTML2 posthtml = posthtml.replace(/\&AFTER_NO\&/g, aPost["after_no"]); } posthtml = posthtml.replace(/\&ID\&/g, aPost["id"]); posthtml = posthtml.replace(/\&TEXT\&/g, aPost["text"]); posthtml = posthtml.replace(/\&TIMESTAMP\&/g, aPost["timestamp"]); var d = new Date(aPost["timestamp"] * 1000); posthtml = posthtml.replace(/\&DATE\&/g, d.toLocaleDateString() + ' (' + day_names[d.getDay()] + ') ' + d.toLocaleTimeString()); posthtml = posthtml.replace(/\&USERNAME\&/g, aPost["username"]); console.log(posthtml); var after_post = document.getElementById('pc' + aPost["after_no"]); console.log(after_post); var post = document.createElement("div"); post.className = "postContainer replyContainer"; post.id = 'pc' + aPost["after_no"]; // if the last post in a thread isn't a valid post based on the id, when the thread updates the whole fugging thread is reloaded. this is a hacky work around sorry. post.innerHTML = posthtml; // add the post after_post.parentNode.insertBefore(post, after_post.nextSibling); return; } // what thread are we in? function getThread() { var thread = document.getElementsByClassName("thread")[0].id; return thread.split('t')[1]; } console.log(getThread()); function LocalMain () { // add in all the posts var client = new HttpClient(); client.get(url+'get.php?thread=' + getThread(), function(response) { var arr = JSON.parse(response); console.log(arr); Object.keys(arr).forEach(function(k) { addPost(arr[k]); }); }); var form = document.createElement("div"); form.innerHTML = '
[s4s] Interface Green Posting Form
Name
Options
Submit:
Comment
' document.getElementsByClassName("thread")[0].parentNode.insertBefore(form, document.getElementsByClassName("thread")[0].nextSibling); } // run this stufffffff window.addEventListener ("load", LocalMain, false);