Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name BetterRedditShare
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author Suppe
- // @match https://old.reddit.com/*
- // @icon https://www.redditstatic.com/desktop2x/img/favicon/favicon-32x32.png
- // @grant GM.setValue
- // @grant GM.getValue
- // @grant GM_xmlhttpRequest
- // @connect 10.0.0.20
- // @connect 10.0.0.21
- // @connect public ip here
- // ==/UserScript==
- (async () => {
- 'use strict';
- var NO_USER_ID = false;
- var user_id_awaited = await GM.getValue("user_id");
- if(user_id_awaited === undefined || user_id_awaited === null || user_id_awaited === ""){
- await GM.setValue("user_id", prompt("Enter your Discord User ID."));
- }
- /*
- var user_id_awaited = await GM.getValue("user_id");
- if(user_id_awaited === undefined || user_id_awaited === null || user_id_awaited === ""){
- NO_USER_ID = true; // Resets after page reload, still allows local title to be replaced
- console.log("NO USER ID PRESENT");
- }
- */
- const USER_ID = await GM.getValue("user_id");
- var lastChangedItem = 0;
- function shareItem (e, url) {
- var target = e.target || e.srcElement;
- console.log(`shareing: "${url}" with user id: "${USER_ID}"`);
- const data = {'user': USER_ID, 'url': url}
- const discord_bot_url = "http://10.0.0.21:8084/share";
- target.style.color = 'DeepPink';
- GM_xmlhttpRequest ( {
- method: "POST",
- url: discord_bot_url,
- data: JSON.stringify(data),
- onload: function (r) {
- switch (r.status) {
- case 200:
- target.style.color = 'green';
- break;
- case 403:
- console.log(r.responseText);
- target.style.color = 'blue';
- break;
- default:
- console.log(r.responseText);
- target.style.color = 'red';
- }
- }
- })
- e.preventDefault();
- }
- function overwriteShare(ele, idx, arr) {
- if (lastChangedItem > idx) return;
- try {
- var PostCommentContainer = ele.querySelector('a[data-event-action="comments"]');
- var post_url = PostCommentContainer.href;
- }
- catch (e) {
- return;
- }
- var shareHeader = ele.querySelector('.share')
- shareHeader.innerHTML = ''
- //<a id="myLink" href="#" onclick="MyFunction();return false;">link text</a>
- var shareButton = document.createElement('a');
- shareButton.id = 'DiscordShare'
- shareButton.href = '#'
- shareButton.onclick = (e) => shareItem(e, post_url)
- shareButton.innerText = 'share'
- shareHeader.appendChild(shareButton);
- lastChangedItem += 1;
- }
- function getAllPosts() {
- if (NO_USER_ID) {
- return;
- }
- var nodes = document.querySelectorAll('div[class^="entry"]')
- nodes.forEach(overwriteShare)
- }
- setInterval(getAllPosts, 1000);
- // Your code here...
- })();
Add Comment
Please, Sign In to add comment