133 lines
4.1 KiB
JavaScript
133 lines
4.1 KiB
JavaScript
// ==UserScript==
|
|
// @name Bing Rewarder
|
|
// @namespace bing
|
|
// @description Utilities to semiautomate Bing reward point redemption
|
|
// @include https://www.bing.com/*
|
|
// @match https://rewards.bing.com/
|
|
// @version 1.6.2
|
|
// @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==
|
|
(function() {
|
|
switch (location.host) {
|
|
case "rewards.bing.com":
|
|
bingRewards();
|
|
break;
|
|
case "bing.com":
|
|
case "www.bing.com":
|
|
bingSearch();
|
|
break;
|
|
}
|
|
|
|
function bingRewards() {
|
|
// Wait times to close tab
|
|
const minBaseTimeout = 3000;
|
|
const maxBaseTimeout = 5000;
|
|
|
|
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");
|
|
|
|
if (link) {
|
|
link.click();
|
|
}
|
|
|
|
const timeoutMs = minBaseTimeout + Math.random() * (maxBaseTimeout - minBaseTimeout);
|
|
setTimeout(() => {
|
|
collectPoint(num+1);
|
|
}, timeoutMs);
|
|
}
|
|
}
|
|
|
|
function bingSearch() {
|
|
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;
|
|
}
|
|
|
|
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<length/2;i++) {
|
|
var randConsonant = consonants[rand(consonants.length)],
|
|
randVowel = vowels[rand(vowels.length)];
|
|
word += (i===0) ? randConsonant.toUpperCase() : randConsonant;
|
|
word += i*2<length-1 ? randVowel : '';
|
|
}
|
|
return word;
|
|
}
|
|
}
|
|
|
|
})();
|