|
@@ -9,12 +9,12 @@
|
|
|
// ==/UserScript==
|
|
|
|
|
|
|
|
|
-//EXTRA OPTIONS
|
|
|
+//EXTRA OPTIONS (disabled by default)
|
|
|
let generate_individual_delete_buttons = false //generate per comment delete and overwrite links
|
|
|
let only_delete_old_comments = false //ignore comments newer than 24 hours
|
|
|
let only_delete_by_subreddit = false //ignore comments from subreddits other than the one chosen in the dropdown
|
|
|
let time_between_actions = 2000 //reddit API limit is 60 actions per minute so don't exceed that
|
|
|
-
|
|
|
+//TODO filter by comment score
|
|
|
|
|
|
// TODO check feedback for Reddit Overwrite for extra features
|
|
|
// TODO consider caching comments array OR not
|
|
@@ -34,6 +34,9 @@ unsafeWindow.div = '';
|
|
|
unsafeWindow.subreddit = "ALL";
|
|
|
unsafeWindow.subreddit_array = [];
|
|
|
|
|
|
+//status text
|
|
|
+unsafeWindow.status_message = null;
|
|
|
+
|
|
|
// on page loaded, initialize the script
|
|
|
window.addEventListener("DOMContentLoaded", init_script, false);
|
|
|
|
|
@@ -67,6 +70,8 @@ function get_comments() {
|
|
|
if (only_delete_by_subreddit && unsafeWindow.subreddit !== "ALL") {
|
|
|
unsafeWindow.comments = [].filter.call(comments, filter_subreddit);
|
|
|
}
|
|
|
+
|
|
|
+ update_status_text();
|
|
|
}
|
|
|
|
|
|
// append buttons to page
|
|
@@ -77,6 +82,42 @@ function generate_top_buttons() {
|
|
|
unsafeWindow.div.innerHTML = "";
|
|
|
unsafeWindow.div.style.marginBottom = "10px";
|
|
|
unsafeWindow.div.style.display = "flex";
|
|
|
+ unsafeWindow.div.style.justifyContent = "flex-start";
|
|
|
+ unsafeWindow.div.style.alignItems = "center";
|
|
|
+
|
|
|
+ // make Subreddit Filter
|
|
|
+ if (only_delete_by_subreddit) {
|
|
|
+ //Create array of subreddits from comments
|
|
|
+ unsafeWindow.subreddit_array = get_subreddit_array();
|
|
|
+
|
|
|
+ let selectList = document.createElement("select");
|
|
|
+ selectList.id = "subredditSelect";
|
|
|
+ selectList.setAttribute('onChange', 'javascript: subreddit_select(this.value)')
|
|
|
+
|
|
|
+ let selectedTitle = document.createElement("option");
|
|
|
+ selectedTitle.selected = true;
|
|
|
+ selectedTitle.disabled = true;
|
|
|
+ selectedTitle.label = "Subreddit";
|
|
|
+ selectList.append(selectedTitle);
|
|
|
+
|
|
|
+ //Create and append the options
|
|
|
+ for (let i = 0; i < unsafeWindow.subreddit_array.length; i++) {
|
|
|
+ let option = document.createElement("option");
|
|
|
+ option.value = unsafeWindow.subreddit_array[i];
|
|
|
+ option.text = unsafeWindow.subreddit_array[i];
|
|
|
+ selectList.appendChild(option);
|
|
|
+ }
|
|
|
+ unsafeWindow.div.appendChild(selectList);
|
|
|
+ }
|
|
|
+
|
|
|
+ // make Status message
|
|
|
+ let status_div = document.createElement("div");
|
|
|
+ status_div.style.marginLeft = "10px";
|
|
|
+ unsafeWindow.status_message = document.createElement("p");
|
|
|
+ unsafeWindow.status_message.setAttribute('class', 'status_message');
|
|
|
+ unsafeWindow.status_message.innerHTML = "FOUND " + unsafeWindow.comments.length + " COMMENTS";
|
|
|
+ status_div.appendChild(unsafeWindow.status_message);
|
|
|
+ unsafeWindow.div.appendChild(status_div);
|
|
|
|
|
|
// make Overwrite and Delete All link
|
|
|
let odlink = document.createElement("a");
|
|
@@ -84,9 +125,7 @@ function generate_top_buttons() {
|
|
|
odlink.setAttribute('onClick', 'javascript: recursive_process(true, true)');
|
|
|
odlink.setAttribute('href', 'javascript:void(0)');
|
|
|
odlink.style.marginLeft = "10px";
|
|
|
- odlink.appendChild(document.createTextNode('OVERWRITE AND DELETE ' +
|
|
|
- unsafeWindow.comments.length +
|
|
|
- ' COMMENTS'));
|
|
|
+ odlink.appendChild(document.createTextNode('OVERWRITE AND DELETE'));
|
|
|
unsafeWindow.div.appendChild(odlink);
|
|
|
let br = document.createElement("br");
|
|
|
unsafeWindow.div.appendChild(br);
|
|
@@ -97,9 +136,7 @@ function generate_top_buttons() {
|
|
|
olink.setAttribute('onClick', 'javascript: recursive_process(true, false)');
|
|
|
olink.setAttribute('href', 'javascript:void(0)');
|
|
|
olink.style.marginLeft = "10px";
|
|
|
- olink.appendChild(document.createTextNode('OVERWRITE ' +
|
|
|
- unsafeWindow.comments.length +
|
|
|
- ' COMMENTS'));
|
|
|
+ olink.appendChild(document.createTextNode('OVERWRITE'));
|
|
|
unsafeWindow.div.appendChild(olink);
|
|
|
let br2 = document.createElement("br");
|
|
|
unsafeWindow.div.appendChild(br2);
|
|
@@ -110,50 +147,13 @@ function generate_top_buttons() {
|
|
|
dlink.setAttribute('onClick', 'javascript: recursive_process(false, true)');
|
|
|
dlink.setAttribute('href', 'javascript:void(0)');
|
|
|
dlink.style.marginLeft = "10px";
|
|
|
- dlink.appendChild(document.createTextNode('DELETE ' +
|
|
|
- unsafeWindow.comments.length +
|
|
|
- ' COMMENTS'));
|
|
|
+ dlink.appendChild(document.createTextNode('DELETE'));
|
|
|
unsafeWindow.div.appendChild(dlink);
|
|
|
|
|
|
- // TODO add status message
|
|
|
- // let status_message = document.createTextNode("p");
|
|
|
- // status_message.innerHTML = "STATUS";
|
|
|
- // status_message.style.marginLeft = "10px";
|
|
|
- // status_message.style.position = "relative";
|
|
|
- // status_message.style.top = "10px";
|
|
|
- // unsafeWindow.span.appendChild(status_message);
|
|
|
-
|
|
|
- // make Subreddit Filter
|
|
|
- //TODO add label
|
|
|
- if (only_delete_by_subreddit) {
|
|
|
- //Create array of subreddits from comments
|
|
|
- unsafeWindow.subreddit_array = get_subreddit_array();
|
|
|
-
|
|
|
- let selectList = document.createElement("select");
|
|
|
- selectList.id = "subredditSelect";
|
|
|
- selectList.style.marginLeft = "10px";
|
|
|
- selectList.setAttribute('onChange', 'javascript: subreddit_select(this.value)')
|
|
|
-
|
|
|
- let selectedTitle = document.createElement("option");
|
|
|
- selectedTitle.selected = true;
|
|
|
- selectedTitle.disabled = true;
|
|
|
- selectedTitle.label = "Subreddit";
|
|
|
- selectList.append(selectedTitle);
|
|
|
-
|
|
|
- //Create and append the options
|
|
|
- for (let i = 0; i < unsafeWindow.subreddit_array.length; i++) {
|
|
|
- let option = document.createElement("option");
|
|
|
- option.value = unsafeWindow.subreddit_array[i];
|
|
|
- option.text = unsafeWindow.subreddit_array[i];
|
|
|
- selectList.appendChild(option);
|
|
|
- }
|
|
|
- unsafeWindow.div.appendChild(selectList);
|
|
|
- }
|
|
|
-
|
|
|
//add our div to the webpage
|
|
|
document.querySelector("div.content").insertBefore(unsafeWindow.div, document.querySelector("div.content").firstChild);
|
|
|
|
|
|
- //add per comment buttons (disabled by default)
|
|
|
+ //add individual comment buttons
|
|
|
if (generate_individual_delete_buttons) unsafeWindow.generate_delete_buttons()
|
|
|
} else if (unsafeWindow.div != null) {
|
|
|
unsafeWindow.div.style.display = 'none';
|
|
@@ -305,6 +305,10 @@ function sort_ignore_caps(a, b) {
|
|
|
return a.toLowerCase().localeCompare(b.toLowerCase());
|
|
|
}
|
|
|
|
|
|
+function update_status_text(){
|
|
|
+ if(unsafeWindow.status_message) unsafeWindow.status_message.innerHTML = "FOUND " + unsafeWindow.comments.length + " COMMENTS"
|
|
|
+}
|
|
|
+
|
|
|
unsafeWindow.overwrite_delete = function (thing_id) {
|
|
|
unsafeWindow.overwrite_comment(thing_id)
|
|
|
unsafeWindow.setTimeout(unsafeWindow.delete_comment, time_between_actions, thing_id)
|