server: tie regex filters to db_insert_ban
[rb-79.git] / example / rb-79.user.js
blob925d9e53d0c4b14b20dee25090b4d98f15bf1a68
1 // ==UserScript==
2 // @name        RB-79 Userscript         [ Change this ]
3 // @namespace   RB-79                    [ Change this ]
4 // @description Fancy features for RB-79 [ Change this ]
5 // @include     http://127.0.0.1/*       [ Change this ]
6 // @version     1
7 // @grant       none
8 // ==/UserScript==
10 var img_re = /\.(png|gif|jpg|webp|jpeg|tif|tiff|bpg|svg)$/i;
11 var video_re = /\.(webm|mkv|mp4|mp3|ogg|m4a|flac|opus|mka)$/i;
14  * Turn off any sort of link for the userscript that's being advertised
15  */
16 document.querySelectorAll('.userscript-link').forEach(function (b) {
17   b.parentNode.removeChild(b);
18 });
21  * Turn all post numbers into clickable links, for quoting and thread-jumping
22  */
23 if (window.location.href.includes('/res/')) {
24   document.querySelectorAll('span.post-number').forEach(function (s) {
25     s.onclick = function () {
26       document.querySelectorAll('textarea[name=comment]').forEach(function (t) {
27         t.value = t.value + '>>' + s.innerText.replace(/No. +/, '') + '\n';
28       });
29     };
30     s.innerHTML = '<a href="#" class="a-subtle">' + s.innerHTML + '</a>';
31   });
32 } else {
33   document.querySelectorAll('div.thread_preview').forEach(function (d) {
34     var thread_url = '';
35     for (var j = 0; j < d.children.length; j++) {
36       var c = d.children[j];
37       if (c.className == 'op-post') {
38         c.querySelectorAll('a').forEach(function (a) {
39           if (a.href.includes('/res/')) {
40             thread_url = a.href;
41           }
42         });
43       }
44       if (c.className == 'op-post' || c.className == 'reply-container') {
45         c.querySelectorAll('span.post-number').forEach(function (s) {
46           var post_number = s.innerText.replace(/No. +/, '');
47           s.innerHTML = '<a href="' + thread_url + '#post' + post_number +
48           '" class="a-subtle">' + s.innerHTML + '</a>';
49         });
50       }
51     }
52   });
56  * Shift+Click to remove files
57  */
58 document.querySelectorAll('input[type=file]').forEach(function (i) {
59   i.title = 'Shift+Click to remove';
60   i.onclick = function (ev) {
61     if (ev.shiftKey) {
62       i.value = '';
63       return false;
64     }
65     return true;
66   };
67 });
70  * Expand images on click
71  */
72 document.querySelectorAll('a.filelink').forEach(function (s) {
73   if (img_re.test(s.href)) {
74     s.onclick = function (ev) {
75       if (ev.which == 2) {
76         return true;
77       }
78       if (!this.expanded) {
79         this.childNodes[0].style.maxWidth = '95vw';
80         this.childNodes[0].style.maxHeight = '95vh';
81         this.expanded = this.childNodes[0].src;
82         this.childNodes[0].src = this.href;
83       } else {
84         this.childNodes[0].src = this.expanded;
85         this.expanded = '';
86       }
87       return false;
88     };
89   } else if (video_re.test(s.href)) {
90     s.onclick = function (ev) {
91       if (ev.which == 2) {
92         return true;
93       }
94       if (!this.expanded) {
95         var aNode = this;
96         aNode.expanded = 'yes';
97         var thumbNode = this.childNodes[0];
98         var parentNode = this.parentNode;
99         thumbNode.style.display = 'none';
100         var videoNode = document.createElement('video');
101         videoNode.src = this.href;
102         videoNode.controls = ' ';
103         videoNode.loop = ' ';
104         videoNode.autoplay = ' ';
105         var closeNode = document.createElement('div');
106         var lBracket = document.createTextNode('[');
107         var closeLink = document.createElement('a');
108         var rBracket = document.createTextNode(']');
109         closeLink.href = '#';
110         closeLink.innerText = 'Close';
111         closeLink.onclick = function (ev1) {
112           thumbNode.style.display = '';
113           aNode.expanded = '';
114           parentNode.removeChild(videoNode);
115           parentNode.removeChild(closeNode);
116           return false;
117         };
118         closeNode.appendChild(lBracket);
119         closeNode.appendChild(closeLink);
120         closeNode.appendChild(rBracket);
121         parentNode.appendChild(closeNode);
122         parentNode.appendChild(videoNode);
123       }
124       return false;
125     };
126   }
130  * IQDB link for images
131  */
132 document.querySelectorAll('a.filelink').forEach(function (s) {
133    if (s.childElementCount > 0 && s.childNodes[0].nodeType == 1 && s.childNodes[0].tagName.toLowerCase() == "img") {
134      return true;
135    }
136    if (img_re.test(s.href)) {
137      var parentNode = s.parentNode;
138      var url = location.protocol + "//iqdb.org/?url=" + s.href;
139      var aNode = document.createElement('a');
140      aNode.href = url;
141      aNode.innerText = "IQDB";
142      var lBracket = document.createTextNode(' [');
143      var rBracket = document.createTextNode(']');
144      parentNode.appendChild(lBracket);
145      parentNode.appendChild(aNode);
146      parentNode.appendChild(rBracket);
147    } else if (video_re.test(s.href)) {
148      var parentNode = s.parentNode;
149      var thumbNode = parentNode.parentNode.childNodes[4].childNodes[0].childNodes[0];
150      var url = location.protocol + "//iqdb.org/?url=" + thumbNode.src;
151      var aNode = document.createElement('a');
152      aNode.href = url;
153      aNode.innerText = "IQDB";
154      var lBracket = document.createTextNode(' [');
155      var rBracket = document.createTextNode(']');
156      parentNode.appendChild(lBracket);
157      parentNode.appendChild(aNode);
158      parentNode.appendChild(rBracket);
159    }
160    return true;