[Share] Customize color labels of reader #211
Replies: 10 comments 23 replies
-
Very nice! thank you very much for this script. |
Beta Was this translation helpful? Give feedback.
-
选中一个条目,shift+enter 在一个独立窗口中打开PDF,在这个独立窗口中动作无效,不知道是我姿势不对?还是? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
It doesn't seem to work anymore for me either - but such a useful addition! Any ideas? |
Beta Was this translation helpful? Give feedback.
-
Just to add that I've also edited lines 10-19 as well - but it didn't make any difference when I restarted Zotero. |
Beta Was this translation helpful? Give feedback.
-
I really appreciate you taking the time to respond but this is what I get after editing 10-19 but returning 56-65 to what they were. |
Beta Was this translation helpful? Give feedback.
-
Interesting! Mine is much longer - 95 lines :( I'll try to print it out and get rid of the surplus. That's very bizarre, as I just copied it from the data bit further up the thread.. Thank you so much though :) |
Beta Was this translation helpful? Give feedback.
-
Cracked it - thank you! I've no idea how that went wrong, but it did. |
Beta Was this translation helpful? Give feedback.
-
Add customize color labels to selection popup and sidebar tag, add space to original context menus /**
* Customize color labels of reader
* @author windingwind
* @editor weihv
* @eidt Add customize color labels to selection popup and sidebar tag, add space to original context menus
* @reference https://www.zotero.org/support/dev/zotero_7_for_developers#custom_reader_event_handlers
* @usage Set the Event to Program Startup; Edit the action script below to replace the labels.
* @link https://github.com/windingwind/zotero-actions-tags/discussions/211
* @see https://github.com/windingwind/zotero-actions-tags/discussions/211
*/
// Edit labels below
const replaceLabelMap = {
"#ffd400": "Custom Yellow",
"#ff6666": "Custom Red",
"#5fb236": "Custom Green",
"#2ea8e5": "Custom Blue",
"#a28ae5": "Custom Purple",
"#e56eee": "Custom Magenta",
"#f19837": "Custom Orange",
"#aaaaaa": "Custom Grey",
};
function hackContextMenuLabel(event) {
setTimeout(() => {
// Check if we are dealing with a context menu
if (event.reader._iframeWindow?.document.querySelector(".context-menu")) {
// This is the context menu case
event.reader._iframeWindow?.document
.querySelectorAll(".context-menu .row")
.forEach((e) => {
const color = e.querySelector("path[fill]")?.getAttribute("fill");
if (!color) {
return;
}
if (color in replaceLabelMap) {
e.innerHTML = e.querySelector("svg")?.outerHTML + " " + replaceLabelMap[color];
}
});
}
}, 10);
}
function hackTextSelectionPopup(event) {
setTimeout(() => {
// Target the text selection popup
const popup = event.reader._iframeWindow?.document.querySelector(".selection-popup");
if (popup) {
// Modify the title of each button
popup.querySelectorAll(".toolbar-button.color-button").forEach((button) => {
const svgElement = button.querySelector("path[fill]");
if (svgElement) {
const color = svgElement.getAttribute("fill");
if (color && replaceLabelMap[color]) {
button.setAttribute("title", replaceLabelMap[color]);
}
}
});
}
}, 10);
}
function hackSidebarAnnotationHeader(event) {
setTimeout(() => {
// Target sidebar bottom selector
const selectorMenu = event.reader._iframeWindow?.document.querySelector(".selector");
if (selectorMenu) {
selectorMenu.querySelectorAll(".color").forEach((button) => {
const svgElement = button.querySelector("path[fill]");
if (svgElement) {
const color = svgElement.getAttribute("fill");
if (color && replaceLabelMap[color]) {
// first line shows label name on color tag
// second line show label name after color tag
button.setAttribute("title", replaceLabelMap[color]); // comment this line if want to show color name on color tag
button.innerHTML = svgElement.closest("svg")?.outerHTML + " " + replaceLabelMap[color];
}
}
});
}
}, 10);
}
// Register event listeners for context menus, popup, selector
// For left sidebar's annotation right-click menu
Zotero.Reader.registerEventListener(
"createAnnotationContextMenu",
hackContextMenuLabel,
"[email protected]"
);
// For top toolbar's color picker menu
Zotero.Reader.registerEventListener(
"createColorContextMenu",
hackContextMenuLabel,
"[email protected]"
);
// For reader text selection popup
Zotero.Reader.registerEventListener(
"renderTextSelectionPopup",
hackTextSelectionPopup,
"[email protected]"
);
// For left sidebar's annotation header (bottom left tag filtering)
Zotero.Reader.registerEventListener(
"renderSidebarAnnotationHeader",
hackSidebarAnnotationHeader,
"[email protected]"
); |
Beta Was this translation helpful? Give feedback.
-
Just learned about scripts and found this one I have wanted for a while. This is an awesome script. Thanks |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Customize color labels of reader. Edit the action script below to replace the labels.
See also #210
Event
Program Startup
Operation
Script
Data
Anything else
No response
Beta Was this translation helpful? Give feedback.
All reactions