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/
20 Hold Control and Shift to hide images, but keep threads open.
21 Doesn't interfere with 4chanx and you can still see images it if you mouse over them.
22 Hidden images reapear in 48 hours.
30 function getDataUri(url) {
35 onload: function (responseDetails) {
46 //var later = Date.now();
48 var start = document.getElementById("postform");
49 if (start === null) start = document.body;
50 else start = start.firstChild;
51 if(!secondObserverSet){
53 observer.disconnect();
54 observeDynamicMutation(start);
55 secondObserverSet = true;
61 if(start === null) return;
62 var itterator = document.createTreeWalker(start, NodeFilter.SHOW_ELEMENTS, NodeFilter.SHOW_ELEMENTS);
66 while((node = itterator.nextNode())){
67 var tag = node.tagName;
69 if(tag == "BLOCKQUOTE"){
70 while((localNode = itterator.nextNode()) && (localTag = localNode.tagName) !== "TABLE"){
71 var localHREF = localNode.href;
72 //console.log(localTag);
73 if(localTag == "A" && (new RegExp("^http(|s):\/\/.+\.(jpg|png|gif|webm|mp4).*$", "g")).test(localHREF)){
74 //console.log("pass3");
75 //console.log(localNode);
77 /*var zeroIndex = localHREF.indexOf("http");
78 var endIndex = localHREF.indexOf(".jpg") + 4;
79 if(endIndex == (-1 + 4)) endIndex = localHREF.indexOf(".png") + 4;
80 if(endIndex == (-1 + 4)) endIndex = localHREF.indexOf(".gif") + 4;
81 if (endIndex == (-1 + 4))endIndex = localHREF.indexOf(".webm") + 5;
82 var urlLink = localHREF.substring(zeroIndex, endIndex);
84 addedImages.forEach(function(url){
91 var parent = node.parentNode;
93 if(localHREF.indexOf(".webm") != -1 | localHREF.indexOf(".mp4") != -1){
94 var vid = document.createElement("VIDEO");
95 vid.setAttribute("src",getDataUri(localHREF));
96 vid.setAttribute("type",getDataUri(localHREF));
97 vid.setAttribute("controls", "true");
99 //img.setAttribute("id","fl" + parent.id.substring(1));
100 vid.addEventListener("load", function(i){
102 this.setAttribute("height",this.height * 0.5);
103 if(this.height < 200) this.height = 200;
104 else if (this.height > 1000)this.height = 1000;
105 else if(this.height == 0){
106 this.setAttribute("src", "https://cs.sankakucomplex.com/data/e8/a4/e8a46437c6ebd2350ac354446a5043c8.webm?4741543");
109 vid.addEventListener("error", function(){
110 this.setAttribute("src", "https://cs.sankakucomplex.com/data/e8/a4/e8a46437c6ebd2350ac354446a5043c8.webm?4741543");
113 parent.insertBefore(vid, node);
115 //addedImages.push(urlLink);
118 var aLink = document.createElement("A");
119 //aLink.setAttribute("class", "fileThumb");
120 //aLink.setAttribute("href", "javascript:void(0);");
121 aLink.setAttribute("href", localHREF);
122 //aLink.setAttribute("target", "_blank");
124 var img = document.createElement("IMG");
125 /*img.setAttribute("onclick",
126 "console.log(\"ets\");\
127 var metaRedirect = document.createElement(\"META\");\
128 metaRedirect.setAttribute(\"http-equiv\",\"refresh\");\
129 metaRedirect.setAttribute(\"id\", \"redir\"); \
130 metaRedirect.setAttribute(\"content\",\"0;" + localHREF + "\");" +
131 "document.head.appendChild(metaRedirect);"
133 //console.log(urlLink);
134 img.setAttribute("src",getDataUri(localHREF));
135 //img.setAttribute("id","fl" + parent.id.substring(1));
136 img.addEventListener("load", function(i){
138 this.setAttribute("height",this.height * 0.5);
139 if(this.height < 200) this.height = 200;
140 else if (this.height > 1000)this.height = 1000;
141 else if(this.height == 0){
142 this.setAttribute("src", "http://orig01.deviantart.net/a920/f/2010/095/9/b/konata_error_404_by_zarkfx.png");
147 img.addEventListener("error", function(){
148 this.setAttribute("src", "http://orig01.deviantart.net/a920/f/2010/095/9/b/konata_error_404_by_zarkfx.png");
151 aLink.appendChild(img);
153 parent.insertBefore(aLink, node);
155 //addedImages.push(urlLink);
159 else if(localTag == "HR"){
169 //initial onload setup
170 function swapListener(){
172 //observeDynamicMutation();
175 //detect page changes
176 function observeDynamicMutation(){
178 var observer = new MutationObserver(function callBack(mutations){
179 var breakVar = false;
181 mutations.forEach(function(mutation){if(mutation.addedNodes[0] !== undefined && mutation.addedNodes[0].className !== undefined && mutation.addedNodes[0].className == "ImageSwap"){breakVar = true;}});
183 var later = Date.now();
185 //console.log("Hide: " + (Date.now() - later));
187 var config = {subtree: true, childList:true};
188 observer.observe(node, config);
191 if (window.top != window.self) //-- Don't run on frames or iframes
195 window.addEventListener("load", function(event){
196 console.log("start");
198 console.log("Script loaded: Swap Images");