Last active
April 7, 2020 19:47
-
-
Save liorrozen/08b074887b96cc8f1648cbdd356c37aa to your computer and use it in GitHub Desktop.
lev_script
This file contains 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
// ==UserScript== | |
// @name Lev_Script | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://gl-tptprod1.transperfect.com/PD/ | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var currentItems = null; | |
var counter = null; | |
counter = setInterval(function(){ | |
if (window.lev_script_on) { | |
var btn = document.getElementsByClassName("mainGrid-refresh-btn")[0]; | |
var grid = document.getElementsByClassName("x-grid-view")[0]; | |
btn.click() | |
console.log("clicked refresh") | |
let numProjects = grid.childNodes[1].childElementCount + grid.childNodes[0].childElementCount; | |
if (currentItems == null) { | |
currentItems = numProjects | |
} | |
let delta = Math.abs(currentItems - numProjects) | |
//grid.childNodes[1].childNodes[1].childNodes[0].childNodes[0].childNodes[1].textContent | |
//grid.childNodes[1].childNodes[1].childNodes[0].childNodes[0].childNodes[1].textContent | |
if (delta > 0) { | |
console.log("Found", numProjects) | |
try { | |
textToSpeech(`Found ${delta} new projects`); | |
window.lev_script_on = false; | |
} catch(err) { | |
// | |
} | |
} | |
} | |
}, 3000); | |
})(); | |
function textToSpeech(text) { | |
// get all voices that browser offers | |
var available_voices = window.speechSynthesis.getVoices(); | |
// this will hold an english voice | |
var english_voice = ''; | |
// find voice by language locale "en-US" | |
// if not then select the first voice | |
for(var i=0; i<available_voices.length; i++) { | |
if(available_voices[i].lang === 'en-US') { | |
english_voice = available_voices[i]; | |
break; | |
} | |
} | |
if(english_voice === '') { | |
english_voice = available_voices[0]; | |
} | |
// new SpeechSynthesisUtterance object | |
var utter = new SpeechSynthesisUtterance(); | |
utter.rate = 1; | |
utter.pitch = 0.5; | |
utter.text = text | |
utter.voice = english_voice; | |
// speak | |
window.speechSynthesis.speak(utter); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment