Created
November 4, 2021 05:24
-
-
Save mpr1255/15ecca4854f069594df112f51c02c8bf to your computer and use it in GitHub Desktop.
make google alerts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// consult here for the explanation, but this is a fixed version based on https://dev.to/frenchcooc/how-to-create-a-bunch-of-google-alerts-in-3-minutes-54n | |
// it has a standard 3 second pause or whatever not some exponential thing that was breaking the code. | |
// also implemented the explanation in the comment section | |
function sleep(milliseconds) { | |
const date = Date.now(); | |
let currentDate = null; | |
do { | |
currentDate = Date.now(); | |
} while (currentDate - date < milliseconds); | |
} | |
var keywords = ["GitHub API", "Google Alerts API", "Dev.to API"] | |
var left = "FILL YOURS IN" | |
var right = "FILL YOURS IN" | |
function addAlert(i) { | |
// Retrieve the keyword to work with | |
const keyword = encodeURIComponent(keywords[i]) | |
//build the params var with the term to be added | |
var params = left + keyword + right | |
console.log(keyword) | |
console.log(params) | |
sleep(5000) | |
// Stop the script if there's no keyword | |
if (!keywords[i] || !keyword) { return; } | |
fetch("https://www.google.com.au/alerts/create?x=AMJHsmX4zQG7yQQkvKClKsfQHbhk0ZIWDQ%3A1635943457897", { | |
"headers": { | |
"accept": "*/*", | |
"accept-language": "en-US,en;q=0.9", | |
"content-type": "application/x-www-form-urlencoded;charset=UTF-8", | |
"sec-fetch-dest": "empty", | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-origin", | |
"sec-gpc": "1" | |
}, | |
"referrer": "https://www.google.com.au/alerts?pli=1", | |
"referrerPolicy": "strict-origin-when-cross-origin", | |
"body": params, | |
"method": "POST", | |
"mode": "cors", | |
"credentials": "include" | |
}); | |
addAlert(i+1); | |
} | |
addAlert(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment