diff --git a/bing-rewarder/index.js b/bing-rewarder/index.js index 840b54d..5384b39 100644 --- a/bing-rewarder/index.js +++ b/bing-rewarder/index.js @@ -1,84 +1,138 @@ // ==UserScript== // @name Bing Rewarder // @namespace bing -// @description Search for 30 random words on bing to rack up reward points, just search bing once to start script +// @description Utilities to semiautomate Bing reward point redemption // @include https://www.bing.com/* -// @version 1.5 +// @match https://rewards.bing.com/ +// @version 1.6 // @updateURL https://git.alexbcberio.com/alexbcberio/userscripts/raw/branch/main/bing-rewarder/index.js // @downloadURL https://git.alexbcberio.com/alexbcberio/userscripts/raw/branch/main/bing-rewarder/index.js // @grant GM.registerMenuCommand // ==/UserScript== - -GM.registerMenuCommand("Start searching", doSearch); - -const urlSearchParams = new URLSearchParams(location.search); -const maxSearch = 30; -const wordMinLength = 4; -const wordMaxLength = 10; -const minWaitSecondsToSearch = 5; -const maxWaitSecondsToSearch = 20; - -if (location.pathname === "/search" && !urlSearchParams.get("rnoreward")) { - newSearch(); -} - -function newSearch() { - let brNum = urlSearchParams.get("brNum"); - - if (brNum == null){ - brNum = 0; - } - brNum = parseInt(brNum) + 1; - - if (isNaN(brNum)) { - brNum = 1; +(function() { + switch (location.host) { + case "rewards.bing.com": + break; + case "bing.com": + case "www.bing.com": + bingSearch(); + break; } - if (brNum > maxSearch){ - return false; + function bingRewards() { + // Wait times to close tab + const minBaseTimeout = 3000; + const maxBaseTimeout = 5000; + // Extra time to wait to perform next click + const minExtraTimeout = 500; + const maxExtraTimeout = 1750; + + const pendingElements = document.querySelectorAll("mee-rewards-points .mee-icon-AddMedium"); + + if (pendingElements.length > 0) { + GM.registerMenuCommand("Collect points", collectPoints); + } + + function collectPoints() { + collectPoint(0); + } + + function collectPoint(num) { + if (!pendingElements[num]) { + return; + } + + const link = pendingElements[num].closest("a"); + const timeoutMs = minBaseTimeout + Math.random() * (maxBaseTimeout - minBaseTimeout); + + if (link) { + const linkLocation = link.getAttribute("href"); + const tab = window.open(linkLocation); + setTimeout(() => { + tab.close(); + }, timeoutMs); + } + + setTimeout(() => { + collectPoint(num+1); + }, timeoutMs + minExtraTimeout + Math.random() * (maxExtraTimeout - minExtraTimeout)); + } } - // timeout to help disguise this as being a script - setTimeout(() => { - doSearch(brNum); - }, (Math.random() * (maxWaitSecondsToSearch - minWaitSecondsToSearch) * 1e3) + minWaitSecondsToSearch * 1e3); -} + function bingSearch() { + GM.registerMenuCommand("Start searching", doSearch); -function doSearch(iteration = 0) { - const wordLength = Math.floor((Math.random() * (wordMaxLength - wordMinLength)) + wordMinLength); - const newQuery = createRandomWord(wordLength); + const urlSearchParams = new URLSearchParams(location.search); + const maxSearch = 30; + const wordMinLength = 4; + const wordMaxLength = 10; + const minWaitSecondsToSearch = 5; + const maxWaitSecondsToSearch = 20; - if (location.pathname === "/") { - const form = document.querySelector("form"); - const searchInput = form.querySelector("[name=q]"); + if (location.pathname === "/search" && !urlSearchParams.get("rnoreward")) { + newSearch(); + } - searchInput.value = newQuery; - form.submit(); - return; + function newSearch() { + let brNum = urlSearchParams.get("brNum"); + + if (brNum == null){ + brNum = 0; + } + brNum = parseInt(brNum) + 1; + + if (isNaN(brNum)) { + brNum = 1; + } + + if (brNum > maxSearch){ + return false; + } + + // timeout to help disguise this as being a script + setTimeout(() => { + doSearch(brNum); + }, (Math.random() * (maxWaitSecondsToSearch - minWaitSecondsToSearch) * 1e3) + minWaitSecondsToSearch * 1e3); + } + + function doSearch(iteration = 0) { + const wordLength = Math.floor((Math.random() * (wordMaxLength - wordMinLength)) + wordMinLength); + const newQuery = createRandomWord(wordLength); + + if (location.pathname === "/") { + const form = document.querySelector("form"); + const searchInput = form.querySelector("[name=q]"); + + searchInput.value = newQuery; + form.submit(); + return; + } + + urlSearchParams.set("q", newQuery); + urlSearchParams.set("brNum", iteration); + + location.search = urlSearchParams.toString(); + } + + + // random word generator script, original source url + // http://james.padolsey.com/javascript/random-word-generator/ + function createRandomWord(desiredLength) { + var consonants = 'bcdfghjklmnpqrstvwxyz'.split(''), + vowels = 'aeiou'.split(''), + rand = function(limit) { + return Math.floor(Math.random()*limit); + }, + i, word='', length = parseInt(desiredLength,10); + for (i=0;i