User:Eejit43/scripts/copy-search-results.js

// // Note: This script was compiled and minified from TypeScript. For a more readable version, see https://github.com/Eejit43/wikipedia-scripts/blob/main/scripts/copy-search-results.ts

"use strict";mw.loader.using(["mediawiki.util"],=>{if(mw.config.get("wgPageName")!=="Special:Search")return;mw.util.addPortletLink(mw.config.get("skin")==="minerva"?"p-navigation":"p-cactions","#","Copy search result titles","copy-search-results").addEventListener("click",t=>{t.preventDefault;const e=[...document.querySelectorAll(".mw-search-result-heading a[data-serp-pos]")].map(r=>r.textContent).join(` `);if(!e)return mw.notify("No search results to copy!",{type:"error"});navigator.clipboard.writeText(e).then(=>mw.notify("Successfully copied search results to clipboard!",{type:"success"}),=>mw.notify("An error occurred when copying search results to clipboard!",{type:"error"}))})});

// //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vc2NyaXB0cy9jb3B5LXNlYXJjaC1yZXN1bHRzLnRzIl0sCiAgInNvdXJjZXNDb250ZW50IjogWyJtdy5sb2FkZXIudXNpbmcoWydtZWRpYXdpa2kudXRpbCddLCAoKSA9PiB7XG4gICAgaWYgKG13LmNvbmZpZy5nZXQoJ3dnUGFnZU5hbWUnKSAhPT0gJ1NwZWNpYWw6U2VhcmNoJykgcmV0dXJuO1xuXG4gICAgY29uc3QgbGluayA9IG13LnV0aWwuYWRkUG9ydGxldExpbmsobXcuY29uZmlnLmdldCgnc2tpbicpID09PSAnbWluZXJ2YScgPyAncC1uYXZpZ2F0aW9uJyA6ICdwLWNhY3Rpb25zJywgJyMnLCAnQ29weSBzZWFyY2ggcmVzdWx0IHRpdGxlcycsICdjb3B5LXNlYXJjaC1yZXN1bHRzJykhO1xuXG4gICAgbGluay5hZGRFdmVudExpc3RlbmVyKCdjbGljaycsIChldmVudCkgPT4ge1xuICAgICAgICBldmVudC5wcmV2ZW50RGVmYXVsdCgpO1xuXG4gICAgICAgIGNvbnN0IHRpdGxlcyA9IFsuLi5kb2N1bWVudC5x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