Created
January 7, 2018 21:46
-
-
Save arthuredelstein/2bf24c38ea7c0d46202bb71cf66977e8 to your computer and use it in GitHub Desktop.
Handy scripts for making screenshots in tor browser. To use, paste in browser console. Then entergrabImage("image-dir", "imagestem", false);
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
let locales = ["ar", "de", /*"en-US",*/ "es-ES", "fa", "fr", "ja", "it", | |
"ko", "nl", "pl", "pt-BR", /*"ru",*/ "tr", "vi", "zh-CN"]; | |
let listenOnce = (element, event, useCapture) => { | |
return new Promise(function (resolve, reject) { | |
let onEvent = function (ev) { | |
element.removeEventListener(event, onEvent, useCapture); | |
resolve(ev); | |
}; | |
element.addEventListener(event, onEvent, useCapture); | |
}); | |
}; | |
let arrayFromEnumerator = (enumerator) => { | |
let arr = []; | |
while (enumerator.hasMoreElements()) { | |
arr.push(enumerator.getNext()); | |
} | |
return arr; | |
}; | |
let directoryContents = (dirPath) => | |
arrayFromEnumerator(new FileUtils.File(dirPath).directoryEntries) | |
.map(x => x.QueryInterface(Ci.nsIFile)); | |
let mostRecentScreenshot = () => | |
directoryContents("/Users/arthur/Desktop") | |
.filter(f => f.leafName.startsWith("Screen Shot")) | |
.sort((a,b) => a.lastModifiedTime - b.lastModifiedTime) | |
.slice(-1)[0]; | |
let moveLatestScreenshotToManual = (locale, location, name) => { | |
let screenShot = mostRecentScreenshot(); | |
let path = `/projects/torproject/user-manual/${locale}/media/${location}/`; | |
screenShot.renameTo(new FileUtils.File(path), name); | |
console.log(`Saved image to ${path}`); | |
}; | |
let userManualDirPath = "/projects/torproject/user-manual/"; | |
let grabImage = async function (locale, mediaSubDir, filename, extra) { | |
console.log(`Current locale: ${locale}`); | |
let shortLocale = locale.substring(0,2); | |
Services.prefs.setCharPref("general.useragent.locale", locale); | |
let win; | |
if (extra === "networkSettings") { | |
win = window.openDialog("chrome://torlauncher/content/network-settings-wizard.xul", "_blank", "chrome,dialog=no,resizable", [true]); | |
} else { | |
win = OpenBrowserWindow(); | |
} | |
await listenOnce(win, "close", false); | |
moveLatestScreenshotToManual(locale, mediaSubDir, filename); | |
}; | |
let grabImages = (mediaSubDir, filename, extra) => { | |
(async function () { | |
for (let locale of locales) { | |
await grabImage(locale, mediaSubDir, filename, extra); | |
} | |
console.log("Finished."); | |
})(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment