-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.min.js
1 lines (1 loc) · 8.12 KB
/
script.min.js
1
if(window.trustedTypes&&window.trustedTypes.createPolicy)window.trustedTypes.createPolicy("default",{createHTML:(e,t)=>e});const BASE_ROOM_PATH=`https://chat.google.com/room`;const quoteSvgIcon=`\n <svg viewBox="0 0 24 24" width="24px" height="24px" xmlns="http://www.w3.org/2000/svg" style="margin-top: 4px">\n <path d="M12 2c5.514 0 10 4.486 10 10s-4.486 10-10 10-10-4.486-10-10 4.486-10 10-10zm0-2c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm0 8v3.701c0 2.857-1.869 4.779-4.5 5.299l-.498-1.063c1.219-.459 2.001-1.822 2.001-2.929h-2.003v-5.008h5zm6 0v3.701c0 2.857-1.869 4.779-4.5 5.299l-.498-1.063c1.219-.459 2.001-1.822 2.001-2.929h-2.003v-5.008h5z"/>\n </svg>`;const extensionCss=`\n .x-chat-copy {\n margin-left: 4px;\n border: 1px solid #dadce0;\n background-color: transparent;\n border-radius: 12px;\n box-sizing: border-box;\n font-family: 'Google Sans',Arial,sans-serif;\n font-size: .875rem;\n font-weight: 500;\n line-height: 1.25rem;\n color: #1967d2;\n padding: 0 12px;\n height: 24px;\n display: inline-flex;\n align-items: center;\n cursor: pointer;\n transition: filter 0.3s ease 0.3s;\n }\n\n .x-chat-copy:hover {\n border-color: transparent;\n box-shadow: 0 1px 2px 0 rgba(60,64,67,0.30), 0 1px 3px 1px rgba(60,64,67,0.15);\n }\n\n .x-chat-copy:active {\n background-color: rgba(26,115,232,0.122);\n }\n\n .x-chat-copy[data-tooltip] {\n position: relative;\n }\n\n /* Base styles for the entire tooltip */\n .x-chat-copy[data-tooltip]:before,\n .x-chat-copy[data-tooltip]:after {\n position: absolute;\n visibility: hidden;\n opacity: 0;\n transition:\n opacity 0.2s ease-in-out,\n visibility 0.2s ease-in-out,\n transform 0.2s cubic-bezier(0.71, 1.7, 0.77, 1.24);\n transform: translate3d(0, 0, 0);\n pointer-events: none;\n }\n\n /* Show the entire tooltip on hover and focus */\n .x-chat-copy[data-tooltip]:hover:before,\n .x-chat-copy[data-tooltip]:hover:after,\n .x-chat-copy[data-tooltip]:focus:before,\n .x-chat-copy[data-tooltip]:focus:after {\n visibility: visible;\n opacity: 1;\n }\n\n /* Base styles for the tooltip's directional arrow */\n .x-chat-copy[data-tooltip]:before {\n z-index: 1001;\n border: 6px solid transparent;\n background: transparent;\n content: "";\n }\n\n /* Base styles for the tooltip's content area */\n .x-chat-copy[data-tooltip]:after {\n z-index: 1000;\n padding: 8px;\n background-color: #000;\n background-color: hsla(0, 0%, 20%, 0.9);\n color: #fff;\n content: attr(data-tooltip);\n font-size: 14px;\n line-height: 1.2;\n }\n\n /* Align tooltips */\n\n .x-chat-copy[data-tooltip]:before,\n .x-chat-copy[data-tooltip]:after {\n bottom: 100%;\n left: 50%;\n }\n\n .x-chat-copy[data-tooltip]:before {\n margin-left: -6px;\n margin-bottom: -12px;\n border-top-color: #000;\n border-top-color: hsla(0, 0%, 20%, 0.9);\n }\n\n .x-chat-copy[data-tooltip]:after {\n margin-left: -30px;\n }\n\n .x-chat-copy[data-tooltip]:hover:before,\n .x-chat-copy[data-tooltip]:hover:after,\n .x-chat-copy[data-tooltip]:focus:before,\n .x-chat-copy[data-tooltip]:focus:after {\n -webkit-transform: translateY(-12px);\n -moz-transform: translateY(-12px);\n transform: translateY(-12px);\n }\n\n #x-clipboard {\n opacity: .01;\n height:0;\n position:absolute;\n z-index: -1;\n }\n\n a[aria-label="Build software better, together, Web Page."],\n a[aria-label="Sign in - Google Accounts, Web Page."],\n a[aria-label="Google Accounts, Web Page."] {\n display: none;\n }\n `;function addStyle(e){var t=document.createElement("style",{type:"text/css"});t.appendChild(document.createTextNode(e));document.head.appendChild(t)}function addThreadClipboard(){var e=document.createElement("textarea");e.setAttribute("id","x-clipboard");document.body.appendChild(e)}function main(){const e=document.querySelector("#x-clipboard");const t=document.querySelectorAll("c-wiz[data-topic-id][data-local-topic-id]");t.forEach(t=>{let n=t.querySelector(".x-chat-copy");if(t.getAttribute("data-topic-id")&&!n){n=document.createElement("div");n.className="x-chat-copy";n.innerHTML=`Copy`;n.addEventListener("click",function(){const o=document.querySelector("c-wiz[data-group-id]").getAttribute("data-group-id").split("/")[1];const a=t.getAttribute("data-topic-id");e.value=`${BASE_ROOM_PATH}/${o}/${a}`;e.select();document.execCommand("copy");n.classList.toggle("bg-active");n.innerHTML=`Copied`;setTimeout(()=>{n.innerHTML=`Copy`;n.classList.toggle("bg-active")},200)});var o=t.querySelector("div:nth-of-type(2) > div:nth-of-type(1) > div:nth-of-type(1) > div:nth-of-type(1) > span:nth-of-type(1)");if(o&&2===o.children.length&&"SPAN"===o.children[0].tagName&&"SPAN"===o.children[1].tagName){o.style="display: inline-block;";o.parentElement.style="display: inline-block; width: unset; opacity: 1;";o.parentElement.parentElement.appendChild(n);o.parentElement.parentElement.parentElement.parentElement.style="padding-top: 56px;";o.parentElement.parentElement.parentElement.style="display: block;"}}const a=t.querySelectorAll('div[jscontroller="VXdfxd"]');a.forEach(e=>{const n=e.parentElement.parentElement.querySelector('[data-tooltip*="Quote Message"');const o=1===e.parentElement.parentElement.children.length;if(n||o)return;const a=document.createElement("div");a.innerHTML=quoteSvgIcon;a.className=e.className;a.setAttribute("data-tooltip","Quote Message");const c=a.children[0];const l=e.querySelector("svg");if(l)l.classList.forEach(e=>c.classList.add(e));else return;var r=e;while(!(r.className&&r.className.includes("nF6pT"))&&r.parentElement)r=r.parentElement;if(r.className.includes("nF6pT")){var i,d;[...r.parentElement.children].forEach((e,t)=>{if(e===r)i=t});e.parentElement.parentElement.appendChild(a);a.addEventListener("click",()=>{while(i>=0){if(r.parentElement.children[i].className.includes("AnmYv")){const e=r.parentElement.children[i].querySelector("[data-hovercard-id], [data-member-id]");d=e.getAttribute("data-name");break}i-=1}var n=e.parentElement.parentElement.parentElement.parentElement.children[0];var o=getQuotedReply(n);let a=t.querySelector('div[contenteditable="true"]');let c=document.body.querySelectorAll('div[contenteditable="true"]');a=a?a:c[c.length-1];if(!a)return;a.innerHTML=formatResponseContent(d,o,a);a.scrollIntoView();a.click();moveCursorToEnd(a)})}})})}function formatResponseContent(e,t,n){return`<span style="color: #9E9E9EFF;"><b>❚ ${e}</b>: <i>${t}</i></span>\n${n.innerHTML}`}function getQuotedReply(e){const t=extractTextContent(e);const n=e.querySelector('a[href*="https://meet.google.com/"]');const o=e.querySelector('a[href*="https://chat.google.com/"]');const a=e.querySelector("a img[alt]");var c=t||(n?`🎥: ${n.href}`:"")||(a?`📷: ${a.alt}`:"")||(o?`💬: ${o.href}`:"");return c.length<280?c:`${c.substring(0,280)} \n[...]`}function extractTextContent(e){const t="FMTudf";const n="jn351e";let o="";const a=e.children[0].childNodes;for(var c=0;c<a.length;c+=1)if(a[c].nodeType===Node.TEXT_NODE)o+=a[c].textContent;else if(a[c].className===n)continue;else if(a[c].className===t)o+="...\n";else if("IMG"===a[c].tagName)o+=a[c].alt;else o+=a[c].innerHTML;return o}function moveCursorToEnd(e){e.focus();if("undefined"!=typeof window.getSelection&&"undefined"!=typeof document.createRange){var t=document.createRange();t.selectNodeContents(e);t.collapse(false);var n=window.getSelection();n.removeAllRanges();n.addRange(t);t.insertNode(document.createElement("br"));t.collapse()}else if("undefined"!=typeof document.body.createTextRange){var o=document.body.createTextRange();o.moveToElementText(e);o.collapse(false);o.select()}}function initialize(){addStyle(extensionCss);addThreadClipboard()}(function(){"use strict";initialize();main();document.documentElement.addEventListener("DOMSubtreeModified",main)})();