// ==UserScript==
// @name Web选择
// @name:en Web Select
// @name:zh-TW Web捕獲
// @namespace http://howardzhangdqs.eu.org/
// @version 0.2.1
// @description 由于Web选择太好用,微软就把他砍掉了。本脚本实现了Web选择的部分功能。按下Alt+S即可选择文本。
// @description:en Due to the ease with which the "web select" was used, Microsoft cut it off. This script implements some functions of "web select". Press Alt+S to select text.
// @description:zh-TW 由於Web選擇功能非常實用,微軟就將它砍掉了。本腳本實現了Web選擇的部分功能。按下Alt+S即可選擇文本。
// @author HowardZhangdqs
// @match *://*/*
// @license MIT
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABsUExURf///xYWFgMDAw4ODgICAh8fHw4ODQAAAA8PD9LS0gEBAR4eHgcHBwoKCgUFBQgICCAgICgoKCwsLB0dHSQkJCYmJvv7+vr6+ZiYlyMjIhwcHJaWlBsbGxgYGAYGBnV2dfz9/BAQEHR0cw0NDWBB0hYAAAFaSURBVFjD7VbZkoMgEARBwNvNsfed///HAJoUq3Ga1a0tH+ynQXragWmtYWzDelEopXzQmgu+/Jorxe9gOtceNjI6gF2X14hC0ic8MZYPBIJwGqonlSzIsHhkkQpu/xlVqKa3D3b7QJ+RLqHAlyRIisICaqkAXYE9YYKMAijYaTGU/0dWu+4+eL9DcjOm1J1DZZQP2jFF6qtARBvNiJK65FxK+TlTwOWnfXyaIZDZB9UvnHhT4HWpQLoJ/KGANcUH/h98EwJzvsSVCST6HiUMKT8EWtyFguyCWdrGxQJHLKCRkYDCzv2+yC644cCY7r78eCOEEd2aC+OHjh3lg2CIGI44TTh8TBupZx0nRxyBnFi4xGYw4rxc1uVKv4U9JGW0M96xeQiFHLoPnNLNtm+LrknTFWIBrgGhQm/oBoSUfAF9S1IjIKdUIF9iO5FF8ChL7it5EzVnG1aMM5cYFmmzQuXPAAAAAElFTkSuQmCC
// @grant none
// ==/UserScript==
(()=>{"use strict";function t(){i(void 0,void 0,void 0,(function(){var t,i,s,c,u,a,p;return l(this,(function(l){switch(l.label){case 0:for(g=[],document.querySelectorAll("*").forEach((function(t){var e=(r=t.getBoundingClientRect()).top,n=r.left,o=r.width,r=r.height;e&&n&&o&&r&&t.innerText&&g.push({top:e,left:n,width:o,height:r,text:t.innerText,src:t})})),t=[],i=0,s=g;i<s.length;i++)c=s[i],t.push((w=void 0,h=c.top,y=c.left,v=c.width,m=c.height,x=c.text,f=c.src,(w=document.createElement("div")).style.position="fixed",w.style.top="".concat(h,"px"),w.style.left="".concat(y,"px"),w.style.width="".concat(v,"px"),w.style.height="".concat(m,"px"),r(w,e),w.style.zIndex="99999",document.body.appendChild(w),{top:h,left:y,width:v,height:m,text:x,el:w,src:f}));return[4,(d=t,new Promise((function(t,i){var l=document.createElement("div"),s=(l.style.position="fixed",l.style.top="0",l.style.left="0",l.style.width="0",l.style.height="0",r(l,o),l.style.borderRadius="6px",l.style.zIndex="99999",document.body.appendChild(l),{p1:[0,0],p2:[0,0],get top(){return Math.min(this.p1[0],this.p2[0])},get left(){return Math.min(this.p1[1],this.p2[1])},get width(){return Math.abs(this.p1[1]-this.p2[1])},get height(){return Math.abs(this.p1[0]-this.p2[0])}}),c=function(t){t.preventDefault(),s.p1=[t.clientY,t.clientX],s.p2=[t.clientY,t.clientX],l.style.top="".concat(s.top,"px"),l.style.left="".concat(s.left,"px"),l.style.width="0",l.style.height="0",document.addEventListener("mousemove",a),document.addEventListener("mouseup",p)},u=function(){return d.filter((function(t){return!(t.left<s.left||t.top<s.top||t.left+t.width>s.left+s.width||t.top+t.height>s.top+s.height)}))},a=function(t){t.preventDefault(),s.p2=[t.clientY,t.clientX],l.style.top="".concat(s.top,"px"),l.style.left="".concat(s.left,"px"),l.style.width="".concat(s.width,"px"),l.style.height="".concat(s.height,"px");for(var o=u(),i=0,c=d;i<c.length;i++){var a=c[i];o.includes(a)?r(a.el,n):r(a.el,e)}},p=function(e){document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",p),document.removeEventListener("mousedown",c),l.remove(),r(document.body,{pointerEvents:""}),t({top:parseInt(l.style.top),left:parseInt(l.style.left),width:parseInt(l.style.width),height:parseInt(l.style.height),el:u()})};document.addEventListener("mousedown",c),document.addEventListener("mouseup",p),r(document.body,{pointerEvents:"none"})})))];case 1:for(p=l.sent(),u=0,a=t;u<a.length;u++)a[u].el.remove();return p=p.el.filter((function(t,e,n){for(var o=0,r=n;o<r.length;o++)if(function(t,e){for(var n=e.parentNode;null!==n;){if(n===t)return!0;n=n.parentNode}return!1}(r[o].src,t.src))return!1;return!0})).sort((function(t,e){return t.left-e.left})).sort((function(t,e){return t.top-e.top})),navigator.clipboard.writeText(p.map((function(t){return t.text})).join("\n\n")),[2]}var d,f,h,y,v,m,x,w,g}))}))}var e={border:"1px solid #fff7",outline:"1px dashed #0007",outlineOffset:"-1px",zIndex:"99999"},n={border:"1px solid #fff",outline:"1px solid #000",outlineOffset:"0",zIndex:"99999"},o={border:"3px dashed red",inlineSize:"0px",zIndex:"99999"},r=function(t,e){for(var n in e)t.style[n]=e[n]},i=function(t,e,n,o){return new(n=n||Promise)((function(r,i){function l(t){try{c(o.next(t))}catch(t){i(t)}}function s(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):((e=t.value)instanceof n?e:new n((function(t){t(e)}))).then(l,s)}c((o=o.apply(t,e||[])).next())}))},l=function(t,e){var n,o,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},l={next:s(0),throw:s(1),return:s(2)};return"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function s(s){return function(c){var u=[s,c];if(n)throw new TypeError("Generator is already executing.");for(;i=l&&u[l=0]?0:i;)try{if(n=1,o&&(r=2&u[0]?o.return:u[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,u[1])).done)return r;switch(o=0,(u=r?[2&u[0],r.value]:u)[0]){case 0:case 1:r=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,o=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(r=0<(r=i.trys).length&&r[r.length-1])&&(6===u[0]||2===u[0])){i=0;continue}if(3===u[0]&&(!r||u[1]>r[0]&&u[1]<r[3]))i.label=u[1];else if(6===u[0]&&i.label<r[1])i.label=r[1],r=u;else{if(!(r&&i.label<r[2])){r[2]&&i.ops.pop(),i.trys.pop();continue}i.label=r[2],i.ops.push(u)}}u=e.call(t,i)}catch(c){u=[6,c],o=0}finally{n=r=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}};window.addEventListener("keydown",(function(e){e.altKey&&"s"===e.key&&t()}))})();