Compare commits

..

2 Commits

Author SHA1 Message Date
blankie c0854ffcb7
Add Archive Site Links 2023-08-22 21:37:06 +10:00
blankie b62b77c652
Update Compass QoL Enhancer to 1.11.0
- Revert making strikethroughs more noticable (this should be done in, say,
userChrome.css)
2023-08-22 21:35:11 +10:00
3 changed files with 121 additions and 10 deletions

111
Archive Site Links.user.js Normal file
View File

@ -0,0 +1,111 @@
// ==UserScript==
// @name Archive Site Links
// @namespace blankie-scripts
// @match http*://*/*
// @grant GM_openInTab
// @grant GM_registerMenuCommand
// @version 1.0.0
// @author blankie
// @description Adds buttons to the monkey menu to open/archive in the Wayback Machine and archive.today
// @inject-into content
// @noframes
// ==/UserScript==
"use strict";
const ARCHIVE_SITES = [
{
name: "Wayback Machine",
getArchiveUrl: function(url) {
let newUrl = new URL("https://web.archive.org/save");
let search = new URLSearchParams([["asl_url", url]]);
newUrl.search = search.toString();
return newUrl.href;
},
getArchivedUrl: function(url) {
return `https://web.archive.org/web/2/${url}`;
},
getArchivedUrlBase: function() {
if (window.location.host !== "web.archive.org") return null;
let match = /^\/web\/[0-9a-z_*]+\/(.+)$/.exec(window.location.pathname);
return match ? match[1] : null;
},
},
{
name: "archive.today",
getArchiveUrl: function(url) {
let newUrl = new URL("https://archive.today");
newUrl.searchParams.append("url", url);
return newUrl.href;
},
getArchivedUrl: function(url) {
return `https://archive.today/newest/${url}`;
},
getArchivedUrlBase: function() {
// https://en.wikipedia.org/wiki/Archive.today?useskin=vector&
if (!/^archive\.(today|ph|is|li|vn|fo|md)$/.test(window.location.host)) return null;
let q = document.querySelector("center form input[name=q]");
return q ? q.value : null;
}
}
];
let url = window.location.href;
let onArchiveSite;
for (const ARCHIVE_SITE of ARCHIVE_SITES) {
let urlBase = ARCHIVE_SITE.getArchivedUrlBase(url);
if (!urlBase) {
continue;
}
if (!/^https?:\/\/|\/\//.test(urlBase)) {
urlBase = `http://${urlBase}`
};
let urlObject = new URL(urlBase);
urlObject.search = window.location.search;
urlObject.hash = window.location.hash;
url = urlObject.href;
onArchiveSite = ARCHIVE_SITE;
break;
}
let archiveSites = 0;
for (const ARCHIVE_SITE of ARCHIVE_SITES) {
if (onArchiveSite === ARCHIVE_SITE) {
continue;
}
if (archiveSites !== 0) {
GM_registerMenuCommand("=".repeat(20) + "\u200B".repeat(archiveSites), function() {});
}
archiveSites++;
GM_registerMenuCommand(`Open in ${ARCHIVE_SITE.name}`, function() {
window.location.href = ARCHIVE_SITE.getArchivedUrl(url);
});
GM_registerMenuCommand(`Open in ${ARCHIVE_SITE.name} (new tab)`, function() {
GM_openInTab(ARCHIVE_SITE.getArchivedUrl(url));
});
let urlObject = new URL(url);
urlObject.hash = "";
let hashlessUrl = urlObject.href;
GM_registerMenuCommand(`Archive in ${ARCHIVE_SITE.name}`, function() {
window.location.href = ARCHIVE_SITE.getArchiveUrl(hashlessUrl);
});
GM_registerMenuCommand(`Archive in ${ARCHIVE_SITE.name} (new tab)`, function() {
GM_openInTab(ARCHIVE_SITE.getArchiveUrl(hashlessUrl));
});
}
// workaround for the wayback machine not exposing a way to prefill the url input box
let searchParams = new URLSearchParams(window.location.search);
if (window.location.host === "web.archive.org" && window.location.pathname === "/save" && searchParams.has("asl_url")) {
document.querySelector("#web-save-url-input").value = searchParams.get("asl_url");
let urlObject = new URL(window.location);
urlObject.searchParams.delete("asl_url");
history.replaceState(null, "", urlObject.href);
}

View File

@ -2,7 +2,7 @@
// @name Compass QoL Enhancer
// @namespace blankie-scripts
// @match http*://*.compass.education/*
// @version 1.10.0
// @version 1.11.0
// @author blankie
// @description A userscript that adds small but useful features for Compass, such as the ability to close windows by clicking on the background
// @inject-into page
@ -132,7 +132,7 @@ function handleNewCalendarEvent(element, calendar) {
// Show the finish time for applicable calendar events
let startString = unsafeWindow.Ext.util.Format.date(calendarData.start, unsafeWindow.Compass.TIME_NO_PERIOD_FORMAT);
let finishString = unsafeWindow.Ext.util.Format.date(calendarData.finish, unsafeWindow.Compass.TIME_NO_PERIOD_FORMAT);
let textElement = a.querySelector("span") || a;
let textElement = a.querySelector(".ext-evt-bd") || a;
// yes, innerHTML. longTitleWithoutTime can apparently contain HTML. lets hope that startString and finishString don't
if (textElement.innerHTML === `${startString}: ${calendarData.longTitleWithoutTime}`) {
textElement.innerHTML = `${startString} - ${finishString}: ${calendarData.longTitleWithoutTime}`;
@ -328,14 +328,10 @@ document.body.addEventListener("click", function(event) {
}
}, {passive: true});
let style = document.createElement("style");
style.textContent = `
/* Make strikethroughs more noticeable on calendar events and their tooltips */
.ext-cal-evt s, .calendar-tip .title s {
text-decoration-thickness: .25em;
// Stop the calendar and email buttons from opening in a new tab
for (let element of document.querySelectorAll("#productNavBar a[target='_blank']")) {
element.removeAttribute("target");
}
`;
document.head.append(style);
// Suppress that annoying barebones context menu that only has Copy
// why is it not obvious that you can just hold ctrl or shift to suppress it???

View File

@ -6,6 +6,11 @@ User scripts I made to deal with some itches
Hacky script to get rid of thot notifications
## Archive Site Links
A userscript that adds buttons to the monkey menu that lets you open sites in
the Wayback Machine and archive.today; also lets you archive pages
## Auto Cloudflare Email Protection Decoder
A reimplementation of Cloudflare's email protection code so that I don't have
@ -23,7 +28,6 @@ A userscript that adds small but useful features for Compass. Features include:
- Calendar events now being links (they work with [Link Hints] now! you can
also ctrl+click on "standard classes", events, and learning tasks)
- Calendar events now show their end time without having to being hovered
- Strikethroughs in calendar events are now a lot more noticeable
- Tabs are now links (you can refresh pages and the tab will automatically
open. you can also ctrl+click on them)
- Files and folders in Resources is now marked clickable ([Link Hints] can now