|
19 | 19 | // @exclude *://stackoverflow.com/c/* |
20 | 20 | // @exclude *://winterbash*.stackexchange.com/* |
21 | 21 | // @exclude *://api.stackexchange.com/* |
22 | | -// @resource iconCheckmark https://cdn.sstatic.net/Img/stacks-icons/Checkmark.svg |
23 | | -// @resource iconClear https://cdn.sstatic.net/Img/stacks-icons/Clear.svg |
24 | | -// @resource iconEyeOff https://cdn.sstatic.net/Img/stacks-icons/EyeOff.svg |
25 | | -// @resource iconFlag https://cdn.sstatic.net/Img/stacks-icons/Flag.svg |
26 | | -// @resource iconPencil https://cdn.sstatic.net/Img/stacks-icons/Pencil.svg |
27 | | -// @resource iconTrash https://cdn.sstatic.net/Img/stacks-icons/Trash.svg |
28 | | -// @resource iconPlus https://cdn.sstatic.net/Img/stacks-icons/Plus.svg |
29 | 22 | // @grant GM_xmlhttpRequest |
30 | 23 | // @grant GM_getValue |
31 | 24 | // @grant GM_setValue |
32 | 25 | // @grant GM_deleteValue |
33 | 26 | // @grant GM_addStyle |
34 | | -// @grant GM_getResourceText |
35 | 27 | // @downloadURL https://github.com/SOBotics/AdvancedFlagging/raw/master/dist/AdvancedFlagging.user.js |
36 | 28 | // @updateURL https://github.com/SOBotics/AdvancedFlagging/raw/master/dist/AdvancedFlagging.user.js |
37 | 29 | // ==/UserScript== |
|
622 | 614 | svg.setAttribute("height", height.toString()); |
623 | 615 | svg.setAttribute("viewBox", `0 0 ${width} ${height}`); |
624 | 616 | svg.setAttribute("aria-hidden", "true"); |
625 | | - const path = document.createElementNS(ns, "path"); |
626 | | - path.setAttribute("d", pathConfig); |
627 | | - svg.append(path); |
628 | | - return [svg, path]; |
| 617 | + if (typeof pathConfig === "string") { |
| 618 | + const path = document.createElementNS(ns, "path"); |
| 619 | + path.setAttribute("d", pathConfig); |
| 620 | + svg.append(path); |
| 621 | + return [svg, path]; |
| 622 | + } else { |
| 623 | + const paths = []; |
| 624 | + pathConfig.forEach((svgPath) => { |
| 625 | + const path = document.createElementNS(ns, "path"); |
| 626 | + path.setAttribute("d", svgPath); |
| 627 | + svg.append(path); |
| 628 | + paths.push(path); |
| 629 | + }); |
| 630 | + return [svg, paths[0]]; |
| 631 | + } |
629 | 632 | }; |
630 | 633 |
|
631 | 634 | // node_modules/@userscripters/stacks-helpers/dist/modals/index.js |
|
808 | 811 | ["Downvote", "downvote"], |
809 | 812 | ["Delete", "delete"] |
810 | 813 | ]; |
811 | | - var getIconPath = (name) => { |
812 | | - const element = GM_getResourceText(name); |
813 | | - const parsed = new DOMParser().parseFromString(element, "text/html"); |
814 | | - const path = parsed.body.querySelector("path"); |
815 | | - return path.getAttribute("d") ?? ""; |
816 | | - }; |
817 | | - var getSvg = (name) => { |
818 | | - const element = GM_getResourceText(name); |
819 | | - const parsed = new DOMParser().parseFromString(element, "text/html"); |
820 | | - return parsed.body.firstElementChild; |
| 814 | + var getIconPath = (svg) => { |
| 815 | + const parsed = new DOMParser().parseFromString(svg, "text/html"); |
| 816 | + const paths = [...parsed.body.querySelectorAll("path")]; |
| 817 | + return paths.map((path) => path.getAttribute("d") ?? ""); |
821 | 818 | }; |
822 | 819 | function displayStacksToast(message, type, dismissable) { |
823 | 820 | StackExchange.helpers.showToast(message, { |
|
1736 | 1733 | } |
1737 | 1734 | }; |
1738 | 1735 |
|
| 1736 | + // node_modules/@stackoverflow/stacks-icons/dist/icons.js |
| 1737 | + var IconCheckmark = '<svg aria-hidden="true" class="svg-icon iconCheckmark" width="18" height="18" viewBox="0 0 18 18"><path d="M16 4.41 14.59 3 6 11.59 2.41 8 1 9.41l5 5z"/></svg>'; |
| 1738 | + var IconClear = '<svg aria-hidden="true" class="svg-icon iconClear" width="18" height="18" viewBox="0 0 18 18"><path d="M15 4.41 13.59 3 9 7.59 4.41 3 3 4.41 7.59 9 3 13.59 4.41 15 9 10.41 13.59 15 15 13.59 10.41 9z"/></svg>'; |
| 1739 | + var IconEyeOff = '<svg aria-hidden="true" class="svg-icon iconEyeOff" width="18" height="18" viewBox="0 0 18 18"><path d="m5.02 9.44-2.22 2.2C1.63 10.25 1 9 1 9s3-6 8.06-6q1.13.01 2.12.38L9.5 5.03 9 5a4 4 0 0 0-3.98 4.44m2.03 3.05A4 4 0 0 0 13 9q-.01-1.1-.54-2l-1.51 1.54q.05.22.05.46a2 2 0 0 1-2.44 1.95zm7.11-7.22A15 15 0 0 1 17 9s-3 6-7.94 6c-1.31 0-2.48-.4-3.5-1l-1.97 2L2 14.41 14.59 2 16 3.41z"/></svg>'; |
| 1740 | + var IconFlag = '<svg aria-hidden="true" class="svg-icon iconFlag" width="18" height="18" viewBox="0 0 18 18"><path d="M3 2v14h2v-6h3.6l.4 1h6V3H9.5L9 2z"/></svg>'; |
| 1741 | + var IconPencil = '<svg aria-hidden="true" class="svg-icon iconPencil" width="18" height="18" viewBox="0 0 18 18"><path fill="#F1B600" d="m2 13.13 8.5-8.5 2.88 2.88-8.5 8.5H2z"/><path fill="#E87C87" d="m13.68 2.15 2.17 2.17c.2.2.2.51 0 .71L14.5 6.39l-2.88-2.88 1.35-1.36c.2-.2.51-.2.71 0"/></svg>'; |
| 1742 | + var IconPlus = '<svg aria-hidden="true" class="svg-icon iconPlus" width="18" height="18" viewBox="0 0 18 18"><path d="M10 2H8v6H2v2h6v6h2v-6h6V8h-6z"/></svg>'; |
| 1743 | + var IconTrash = '<svg aria-hidden="true" class="svg-icon iconTrash" width="18" height="18" viewBox="0 0 18 18"><path d="M15 2a1 1 0 0 1 1 1v1H2V3a1 1 0 0 1 1-1h2a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1zm0 3H3v10c0 1.1.9 2 2 2h8a2 2 0 0 0 2-2z"/></svg>'; |
| 1744 | + |
1739 | 1745 | // src/UserscriptTools/Post.ts |
1740 | 1746 | var Post = class _Post { |
1741 | 1747 | constructor(element) { |
|
1771 | 1777 | score; |
1772 | 1778 | static getActionIcons() { |
1773 | 1779 | return [ |
1774 | | - ["Checkmark", "fc-green-500"], |
1775 | | - ["Clear", "fc-red-500"], |
1776 | | - ["Flag", "fc-red-500"] |
1777 | | - ].map(([svg, classname]) => _Post.getIcon(getSvg(`icon${svg}`), classname)); |
| 1780 | + [IconCheckmark, "fc-green-500"], |
| 1781 | + [IconClear, "fc-red-500"], |
| 1782 | + [IconFlag, "fc-red-500"] |
| 1783 | + ].map(([svg, classname]) => _Post.getIcon(svg, classname)); |
1778 | 1784 | } |
1779 | 1785 | async flag(reportType, text) { |
1780 | 1786 | const flagName = getFlagToRaise(reportType, this.qualifiesForVlq()); |
|
1992 | 1998 | }); |
1993 | 1999 | return Object.fromEntries(newEntries); |
1994 | 2000 | } |
1995 | | - static getIcon(svg, classname) { |
| 2001 | + static getIcon(element, classname) { |
| 2002 | + const parsed = new DOMParser().parseFromString(element, "text/html"); |
| 2003 | + const svg = parsed.querySelector("svg"); |
1996 | 2004 | const wrapper = document.createElement("div"); |
1997 | 2005 | wrapper.classList.add("flex--item"); |
1998 | 2006 | wrapper.style.display = "none"; |
|
2018 | 2026 | text, |
2019 | 2027 | icon: [ |
2020 | 2028 | "iconEyeOff", |
2021 | | - getIconPath("iconEyeOff") |
| 2029 | + getIconPath(IconEyeOff)[0] |
2022 | 2030 | ], |
2023 | 2031 | classes: ["mb16"] |
2024 | 2032 | }); |
|
2981 | 2989 | const h3 = getH3(input?.value ?? ""); |
2982 | 2990 | input?.parentElement?.replaceWith(h3); |
2983 | 2991 | } |
2984 | | - const pencil = getIconPath("iconPencil"); |
2985 | | - const eyeOff = getIconPath("iconEyeOff"); |
2986 | 2992 | const [svg, , text] = [...edit.childNodes]; |
2987 | | - svg.classList.toggle("iconPencil"); |
2988 | | - svg.classList.toggle("iconEyeOff"); |
2989 | | - svg.firstElementChild?.setAttribute("d", isExpanded ? eyeOff : pencil); |
| 2993 | + svg.insertAdjacentHTML("afterend", isExpanded ? IconEyeOff : IconPencil); |
| 2994 | + svg.remove(); |
2990 | 2995 | text.textContent = isExpanded ? " Hide" : "Edit"; |
2991 | 2996 | isExpanded ? $(save).fadeIn("fast") : $(save).fadeOut("fast"); |
2992 | 2997 | } |
|
3007 | 3012 | { |
3008 | 3013 | iconConfig: { |
3009 | 3014 | name: "iconPencil", |
3010 | | - path: getIconPath("iconPencil"), |
| 3015 | + path: getIconPath(IconPencil), |
3011 | 3016 | height: 18, |
3012 | 3017 | width: 18 |
3013 | 3018 | }, |
|
3025 | 3030 | type: ["danger"], |
3026 | 3031 | iconConfig: { |
3027 | 3032 | name: "iconTrash", |
3028 | | - path: getIconPath("iconTrash"), |
| 3033 | + path: getIconPath(IconTrash), |
3029 | 3034 | width: 18, |
3030 | 3035 | height: 18 |
3031 | 3036 | }, |
|
3132 | 3137 | type: ["outlined"], |
3133 | 3138 | iconConfig: { |
3134 | 3139 | name: "iconPlus", |
3135 | | - path: getIconPath("iconPlus"), |
| 3140 | + path: getIconPath(IconPlus), |
3136 | 3141 | height: 18, |
3137 | 3142 | width: 18 |
3138 | 3143 | } |
|
0 commit comments