Skip to content

Instantly share code, notes, and snippets.

@FrostBird347
Last active December 12, 2023 10:50
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 FrostBird347/82473292f6d84542b607b87c2ea61df5 to your computer and use it in GitHub Desktop.
Save FrostBird347/82473292f6d84542b607b87c2ea61df5 to your computer and use it in GitHub Desktop.
A simple BetterDiscord plugin that hides the sent time of recent posts, allowing you to take screenshots without giving away your timezone.
/**
* @name HideTime
* @authorLink https://github.com/FrostBird347
* @source https://gist.github.com/FrostBird347/82473292f6d84542b607b87c2ea61df5#gistcomment-3376137
* @updateUrl https://gist.githubusercontent.com/FrostBird347/82473292f6d84542b607b87c2ea61df5/raw/HideTime.plugin.js
*/
module.exports = class HideTime {
getName() {return "HideTime";}
getDescription() {return "Hides the timestamps of recent posts, allowing you to take screenshots without giving away your timezone.";}
getVersion() {return "1.0.15";}
getAuthor() {return "FrostBird347";}
load() {}
stop() {
window.clearInterval(window.HTSlowSearchID);
delete window.HTSlowSearchID;
delete window.TryHideTime;
}
start() {
//Simple update notifier
//I have been unable to figure out how to obtain the plugin's version
let CurrentVersion = "1.0.15";
window.fetch("https://gist.githubusercontent.com/FrostBird347/82473292f6d84542b607b87c2ea61df5/raw/HideTime.plugin.js").then(function(response) {
response.text().then(function(text) {
let Lines = text.split("\t").join("").split("\n");
let RemoteVersion = "";
for (let l = 0; l < Lines.length; l++) {
if (RemoteVersion == "" && Lines[l].split(" ").join("").split("\"")[0] == "getVersion(){return") {
RemoteVersion = Lines[l].split(" ").join("").split("\"")[1];
}
}
if (RemoteVersion != CurrentVersion) {
window.BdApi.UI.showToast("HideTime is outdated!\nCurrent: " + CurrentVersion + "\nLatest: " + RemoteVersion, {type: "info", icon:true, timeout: 7500});
}
});
});
window.TryHideTime = function(el) {
try {
if (!el.classList.contains("HTAlreadyDone")) {
if (el.innerText.replace(" — \n", "").startsWith("Today at ") && !el.innerText.replace(" — \n", "").startsWith("Today at --:--")) {
el.innerText = "Today at --:--";
} else if (el.innerText.replace(" — \n", "").startsWith("Yesterday at ") && !el.innerText.replace(" — \n", "").startsWith("Yesterday at --:--")) {
el.innerText = "Yesterday at --:--";
} else if (el.innerText.replace(" — \n", "").replace(", ", " ").split(" ").length >= 2) {
el.innerText = el.innerText.replace(" — \n", "").replace(", ", " ").split(" ")[0];
}
el.classList.add("HTAlreadyDone")
}
} catch {}
}
window.HTSlowSearchID = window.setInterval(function(){
let TimeList = document.body.getElementsByTagName("TIME");
for (let i = 0; i < TimeList.length; i++) {
window.TryHideTime(TimeList[i]);
}
}, 5000);
}
observer(changes) {
//window.console.log(changes);
for (let i = 0; i < changes.addedNodes.length; i++) {
try {
//window.console.log(changes.addedNodes[i]);
if (!["LI", "SPAN", "MAIN"].includes(changes.addedNodes[i].tagName) && !changes.addedNodes[i].classList.contains("backgroundFlash_e5b9ad")) {
throw "Skipped, element likely isn't a new timestamp"
}
//window.console.log("^ PASSED");
Array.prototype.forEach.call(changes.addedNodes[i].getElementsByTagName("TIME"), function(el) {
window.TryHideTime(el);
})
} catch {}
}
}
}
@FrostBird347
Copy link
Author

FrostBird347 commented Jul 14, 2020

Source ↑

Update Log

1.0.15

  • Fix older messages not having their timestamp removed
    • Discord changed the timestamp format for seemingly no reason

1.0.14

  • Updated deprecated BdApi functions

1.0.13

  • Discord changed the class names of everything

1.0.12

  • Added another slower fallback check that's run once every 5 seconds

1.0.11

  • Fixed another bug that was causing messages to not be checked under some conditions

1.0.10

  • Fixed a bug that was causing messages to not be checked under some conditions

1.0.9

  • Optimised code
    • Timestamps are only searched for in relevant elements and only when they are created, instead of searching the entire page each time anything is changed (I can't believe that I didn't fix this issue earlier)

1.0.8

  • Improved variable declaration

1.0.7

  • Now removes timestamps from older messages (which previously didn't have a timestamp)

1.0.6

  • Added an extremely simple update notifier

1.0.5

  • Fix bug preventing timestamps from being removed

1.0.4

  • Added update link

1.0.3

  • Updated source link to take the user to this change log
  • Added author link

1.0.2

  • Removed timestamps are now ignored
  • Timestamp removal is called through observer() instead of window.setInterval()

1.0.1

  • Updated source link

1.0.0

  • Uploaded plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment