Skip to content

Commit 66701ff

Browse files
authored
Create recyclescript.user.js
1 parent ee27f38 commit 66701ff

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

recyclescript.user.js

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// ==UserScript==
2+
// @name RecycleScript
3+
// @version 0.1
4+
// @description Allows you to quote without quotes
5+
// @author Jomity
6+
// @match *://artofproblemsolving.com/*
7+
// ==/UserScript==
8+
9+
(function() {
10+
'use strict';
11+
12+
function waitForElementToDisplay(selector, callback, checkFrequencyInMs, timeoutInMs) {
13+
var startTimeInMs = Date.now();
14+
(function loopSearch() {
15+
if (document.querySelector(selector) != null) {
16+
callback();
17+
return;
18+
}
19+
else {
20+
setTimeout(function () {
21+
if (timeoutInMs && Date.now() - startTimeInMs > timeoutInMs) {
22+
return;
23+
}
24+
loopSearch();
25+
}, checkFrequencyInMs);
26+
}
27+
})();
28+
}
29+
30+
window.addEventListener('load', function() {
31+
for (let i = 0; i < 60000; i++) {
32+
setTimeout(function timer() {
33+
let posts = document.getElementsByClassName("cmty-post-right");
34+
for (let j = 0; j < posts.length; j++) {
35+
if (posts[j].children[posts[j].children.length-1].innerHTML !== 'r') {
36+
let element = document.createElement("span");
37+
posts[j].appendChild(element);
38+
39+
element.title="Repost this post";
40+
element.innerHTML = "r";
41+
element.classList.add("cmty-post-repost");
42+
element.classList.add("aops-font");
43+
element.onclick = function() {
44+
var quote = element.parentNode.getElementsByClassName("cmty-post-quote")[0];
45+
46+
var lastValue = null;
47+
if (document.getElementsByClassName("cmty-post-textarea").length > 0) {
48+
if (quote.closest("#feed-left") == null) {
49+
lastValue = document.getElementsByClassName("cmty-post-textarea")[0].value;
50+
}
51+
else if (quote.closest("#feed-left").querySelector("textarea")) {
52+
lastValue = quote.closest("#feed-left").querySelector("textarea").value;
53+
}
54+
}
55+
56+
quote.click();
57+
58+
if (quote.closest("#feed-left") == null) {
59+
waitForElementToDisplay(".cmty-post-textarea", function() {
60+
let t = document.getElementsByClassName("cmty-post-textarea")[0].value;
61+
t = t.replace(lastValue,'');
62+
document.getElementsByClassName("cmty-post-textarea")[0].value = t.substring(t.indexOf(']') + 1).slice(0, -10);
63+
}, 5, 200);
64+
}
65+
else {
66+
setTimeout(function() {
67+
let t = quote.closest("#feed-left").querySelector("textarea").value;
68+
quote.closest("#feed-left").querySelector("textarea").value = t.substring(t.indexOf(']') + 1).slice(0, -10);
69+
}, 20);
70+
}
71+
};
72+
}
73+
}
74+
75+
}, i * 200);
76+
}
77+
}, false);
78+
})();

0 commit comments

Comments
 (0)