3 // @namespace http://tampermonkey.net/
5 // @description Add images to your posts
6 // @author ECHibiki-/qa/
7 // @match http://warosu.org/*
8 // @match https://warosu.org/*
9 // @include http://warosu.org/*
10 // @include https://warosu.org/*
11 // @run-at document-body
14 // @grant GM_xmlhttpRequest
15 // @connect https://danbooru.donmai.us/
16 // @connect http://danbooru.donmai.us/
17 // @updateURL https://github.com/ECHibiki/Misc-UserScripts/raw/master/Warosu-Images.user.js
18 // @downloadURL https://github.com/ECHibiki/Misc-UserScripts/raw/master/Warosu-Images.user.js
22 Hold Control and Shift to hide images, but keep threads open.
23 Doesn't interfere with 4chanx and you can still see images it if you mouse over them.
24 Hidden images reapear in 48 hours.
32 function getDataUri(url) {
37 onload: function (responseDetails) {
48 //var later = Date.now();
50 var start = document.getElementById("postform");
51 if (start === null) start = document.body;
52 else start = start.firstChild;
53 if(!secondObserverSet){
55 observer.disconnect();
56 observeDynamicMutation(start);
57 secondObserverSet = true;
63 if(start === null) return;
64 var itterator = document.createTreeWalker(start, NodeFilter.SHOW_ELEMENTS, NodeFilter.SHOW_ELEMENTS);
68 while((node = itterator.nextNode())){
69 var tag = node.tagName;
71 if(tag == "BLOCKQUOTE"){
72 while((localNode = itterator.nextNode()) && (localTag = localNode.tagName) !== "TABLE"){
73 var localHREF = localNode.href;
74 //console.log(localTag);
75 if(localTag == "A" && (new RegExp("^http(|s):\/\/.+\.(jpg|png|gif|webm|mp4).*$", "g")).test(localHREF)){
76 //console.log("pass3");
77 //console.log(localNode);
79 /*var zeroIndex = localHREF.indexOf("http");
80 var endIndex = localHREF.indexOf(".jpg") + 4;
81 if(endIndex == (-1 + 4)) endIndex = localHREF.indexOf(".png") + 4;
82 if(endIndex == (-1 + 4)) endIndex = localHREF.indexOf(".gif") + 4;
83 if (endIndex == (-1 + 4))endIndex = localHREF.indexOf(".webm") + 5;
84 var urlLink = localHREF.substring(zeroIndex, endIndex);
86 addedImages.forEach(function(url){
93 var parent = node.parentNode;
95 if(localHREF.indexOf(".webm") != -1 | localHREF.indexOf(".mp4") != -1){
96 var vid = document.createElement("VIDEO");
97 vid.setAttribute("src",getDataUri(localHREF));
98 vid.setAttribute("type",getDataUri(localHREF));
99 vid.setAttribute("controls", "true");
101 //img.setAttribute("id","fl" + parent.id.substring(1));
102 vid.addEventListener("load", function(i){
104 this.setAttribute("height",this.height * 0.5);
105 if(this.height < 200) this.height = 200;
106 else if (this.height > 1000)this.height = 1000;
107 else if(this.height == 0){
108 this.setAttribute("src", "https://cs.sankakucomplex.com/data/e8/a4/e8a46437c6ebd2350ac354446a5043c8.webm?4741543");
111 vid.addEventListener("error", function(){
112 this.setAttribute("src", "https://cs.sankakucomplex.com/data/e8/a4/e8a46437c6ebd2350ac354446a5043c8.webm?4741543");
115 parent.insertBefore(vid, node);
117 //addedImages.push(urlLink);
120 var aLink = document.createElement("A");
121 //aLink.setAttribute("class", "fileThumb");
122 //aLink.setAttribute("href", "javascript:void(0);");
123 aLink.setAttribute("href", localHREF);
124 //aLink.setAttribute("target", "_blank");
126 var img = document.createElement("IMG");
127 /*img.setAttribute("onclick",
128 "console.log(\"ets\");\
129 var metaRedirect = document.createElement(\"META\");\
130 metaRedirect.setAttribute(\"http-equiv\",\"refresh\");\
131 metaRedirect.setAttribute(\"id\", \"redir\"); \
132 metaRedirect.setAttribute(\"content\",\"0;" + localHREF + "\");" +
133 "document.head.appendChild(metaRedirect);"
135 //console.log(urlLink);
136 img.setAttribute("src",getDataUri(localHREF));
137 //img.setAttribute("id","fl" + parent.id.substring(1));
138 img.addEventListener("load", function(i){
140 this.setAttribute("height",this.height * 0.5);
141 if(this.height < 200) this.height = 200;
142 else if (this.height > 1000)this.height = 1000;
143 else if(this.height == 0){
144 this.setAttribute("src", "http://orig01.deviantart.net/a920/f/2010/095/9/b/konata_error_404_by_zarkfx.png");
149 img.addEventListener("error", function(){
150 this.setAttribute("src", "http://orig01.deviantart.net/a920/f/2010/095/9/b/konata_error_404_by_zarkfx.png");
153 aLink.appendChild(img);
155 parent.insertBefore(aLink, node);
157 //addedImages.push(urlLink);
161 else if(localTag == "HR"){
171 //initial onload setup
172 function swapListener(){
174 //observeDynamicMutation();
177 //detect page changes
178 function observeDynamicMutation(){
180 var observer = new MutationObserver(function callBack(mutations){
181 var breakVar = false;
183 mutations.forEach(function(mutation){if(mutation.addedNodes[0] !== undefined && mutation.addedNodes[0].className !== undefined && mutation.addedNodes[0].className == "ImageSwap"){breakVar = true;}});
185 var later = Date.now();
187 //console.log("Hide: " + (Date.now() - later));
189 var config = {subtree: true, childList:true};
190 observer.observe(node, config);
193 if (window.top != window.self) //-- Don't run on frames or iframes
197 window.addEventListener("load", function(event){
198 console.log("start");
200 console.log("Script loaded: Swap Images");