Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/addons.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"no-sprite-confirm",
"costume-editor-shortcuts",
"live-read-topics",
"show-full-text",

"// NEW ADDONS ABOVE THIS ↑↑",
"// Note: these themes need this exact order to work properly,",
Expand Down
20 changes: 20 additions & 0 deletions addons/show-full-text/addon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "Show full text on hover",
"description": "Hover your mouse over overflowed text on profile pages and studios to see the full text.",
"credits": [
{
"name": "mysinginmonsters",
"link": "https://scratch.mit.edu/users/mysinginmonsters/"
}
],
"tags": ["community", "profiles", "studios"],
"userscripts": [
{
"url": "userscript.js",
"matches": ["https://scratch.mit.edu/users/*", "studios"]
}
],
"dynamicEnable": true,
"dynamicDisable": true,
"versionAdded": "1.44.0"
}
77 changes: 77 additions & 0 deletions addons/show-full-text/userscript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
export default async function ({ addon, console }) {
const MODE_ADD = 1;
const MODE_REMOVE = 2;

function addTitle(textItem, mode) {
if (textItem) {
if (mode == 1) {
textItem.setAttribute("title", textItem.innerHTML);
} else if (mode == 2) {
if (textItem.hasAttribute("title")) {
textItem.removeAttribute("title");
}
}
}
}

function setTitlesInProfile(mode) {
// Select overflowed items on profiles
const profileItems = document.querySelectorAll("li.project.thumb.item, li.gallery.thumb.item, li.user.thumb.item");
// Add title attribute to all
profileItems.forEach((i) => {
addTitle(i.querySelector("span.title").querySelector("a"), mode);
});
}

function setTitlesInStudio(mode) {
// Select overflowed items on studios
const studioItems = document.querySelectorAll(
"a.studio-project-title, a.studio-project-username, a.studio-member-name"
);
// Add title attribute to all
studioItems.forEach((i) => {
addTitle(i, mode);
});
}

// Add titles when page loads
setTitlesInProfile(MODE_ADD);
setTitlesInStudio(MODE_ADD);

// When document is changed
function domChanged(mutations, observer) {
mutations.forEach((i) => {
i.addedNodes.forEach((node) => {
// If added node is an element
if (node.nodeType == 1) {
if (addon.self.disabled) {
setTitlesInProfile(MODE_REMOVE);
setTitlesInStudio(MODE_REMOVE);
} else {
setTitlesInProfile(MODE_ADD);
setTitlesInStudio(MODE_ADD);
}
}
});
});
}

// Set up observer
const observer = new MutationObserver(domChanged);

observer.observe(document.body, {
childList: true,
subtree: true,
});

// Remove all title attributes on disable
addon.self.addEventListener("disabled", () => {
setTitlesInProfile(MODE_REMOVE);
setTitlesInStudio(MODE_REMOVE);
});

addon.self.addEventListener("reenabled", () => {
setTitlesInProfile(MODE_ADD);
setTitlesInStudio(MODE_ADD);
});
}
Loading