Skip to content

Instantly share code, notes, and snippets.

@csm10495
Last active October 21, 2023 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csm10495/47c900978866770cdff934f6cd783665 to your computer and use it in GitHub Desktop.
Save csm10495/47c900978866770cdff934f6cd783665 to your computer and use it in GitHub Desktop.
Google Messages Archiver
// ==UserScript==
// @name Google Messages Archiver
// @namespace Whatever
// @match https://messages.google.com/web/*
// @grant GM_log
// @author csm10495
// @description Run doIt() in the console to archive all conversations after the most recent 5.
// @version 0.1.0
// ==/UserScript==
// I had a lot of conversations that I wanted to archive.. this script used via the console/tampermonkey does that for me as a one-off.
// This script is released via the MIT License - 2023. For a copy of it see https://opensource.org/license/mit/
function getMatches() {
var matches = document.querySelector("mws-conversations-list").querySelectorAll('.mat-mdc-button-touch-target');
return matches
}
function findAndClickArchive() {
let textItems = document.querySelectorAll('.mat-mdc-menu-item-text');
for (let i = 0; i < textItems.length; i++) {
if (textItems[i].textContent == "Archive") {
textItems[i].click();
GM_log("found!");
break;
}
else {
GM_log(textItems[i].textContent);
}
}
GM_log("not found!");
}
function clickArchiveOnMatch(match) {
match.click();
setTimeout(function () {
findAndClickArchive();
}, 100);
}
function doIt() {
let matches = getMatches();
if (matches.length < 6) {
return;
}
clickArchiveOnMatch(matches[5]);
setTimeout(doIt, 200);
}
unsafeWindow.getMatches = getMatches;
unsafeWindow.clickArchiveOnMatch = clickArchiveOnMatch;
unsafeWindow.doIt = doIt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment