forked from hlfbt/AnimeBytes-Userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ab_autobookmark.user.js
35 lines (31 loc) · 1.39 KB
/
ab_autobookmark.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// ==UserScript==
// @name AnimeBytes autobookmark
// @author potatoe
// @version 0.5
// @description Automatically bookmark threads created or posted to.
// @include *animebytes.tv/forums.php*
// @include *animebyt.es/forums.php*
// @icon http://animebytes.tv/favicon.ico
// ==/UserScript==
function injectScript (content, id) {
var script = document.createElement('script');
if (id) script.setAttribute('id', id);
script.textContent = content.toString();
document.body.appendChild(script);
return script;
}
function autoBookmark() {
var bookmarkNode = document.getElementById('bookmark');
if (bookmarkNode.textContent === '[Bookmark]') {
var bookmarkLink = bookmarkNode.getAttribute('href') + '&ajax=1';
var bookmarkXmlhttp = new XMLHttpRequest();
bookmarkXmlhttp.open('GET', bookmarkLink, false);
bookmarkXmlhttp.send();
}
}
var quickpostformNode = document.getElementById('quickpostform'), bookmarkNode = document.getElementById('bookmark'), post_wrapNodes = document.getElementsByClassName('post_wrap');
if (bookmarkNode && post_wrapNodes && post_wrapNodes.length === 1 && document.referrer.match(/.*[?&]action=new.*/) && document.location.search.match(/.*[?&]action=viewthread.*/)) autoBookmark();
if (bookmarkNode && quickpostformNode) {
injectScript(autoBookmark, 'autobookmark');
quickpostformNode.setAttribute('onsubmit', 'autoBookmark();' + quickpostformNode.getAttribute('onsubmit'));
}