├── FlowCircular-Regular.ttf ├── README.md └── redactor.user.js /FlowCircular-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easrng/redactor/8d96fd66018459a35b7e2b744f3ef575cb743851/FlowCircular-Regular.ttf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # redactor [![add userscript](https://img.shields.io/badge/-add%20userscript-gray)](https://easrng.github.io/redactor/redactor.user.js) 2 | A userscript for redacting things, as requested by [@maris@chaos.social](https://chaos.social/@maris). 3 | 4 | [A screenshot of a redacted post on Mastodon](https://chaos.social/@maris/108379392423588799) 5 | 6 | ## How do you use it? 7 | Select some text and click the "Redact" menu item. Where it is probably depends on what userscript addon you use, but here's how it looks in ViolentMonkey: 8 | 9 | A screenshot of the ViolentMonkey popup showing the redact menu item. 10 | 11 | 12 | ## This doesn't work on some sites, how do I fix it? 13 | Some sites have security restrictions that make it so the userscript can't load the font. To fix it, install the [Flow Circular](https://easrng.github.io/redactor/FlowCircular-Regular.ttf) font. 14 | 15 | ## How does it work? 16 | It's just [a JS library that hasn't been updated since 2015](https://github.com/timdown/rangy) and a [special font](https://danross.co/flow/) in a trenchcoat. 17 | -------------------------------------------------------------------------------- /redactor.user.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name Redactor 3 | // @namespace https://easrng.net 4 | // @match *://*/* 5 | // @grant GM_registerMenuCommand 6 | // @version 1.0 7 | // @author easrng 8 | // @description A userscript for redacting things 9 | // @downloadURL https://easrng.github.io/redactor/redactor.user.js 10 | // @run-at document-end 11 | // ==/UserScript== 12 | !function(e,t){"function"==typeof define&&define.amd?define(e):"undefined"!=typeof module&&"object"==typeof exports?module.exports=e():t.rangy=e()}(function(){function e(e,t){var n=typeof e[t];return n==R||!(n!=m||!e[t])||"unknown"==n}function t(e,t){return!(typeof e[t]!=m||!e[t])}function n(e,t){return typeof e[t]!=v}function r(e){return function(t,n){for(var r=n.length;r--;)if(!e(t,n[r]))return!1;return!0}}function o(e){return e&&y(e,S)&&T(e,E)}function i(e){return t(e,"body")?e.body:e.getElementsByTagName("body")[0]}function a(t){typeof console!=v&&e(console,"log")&&console.log(t)}function s(e,t){D&&t?alert(e):a(e)}function c(e){x.initialized=!0,x.supported=!1,s("Rangy is not supported in this environment. Reason: "+e,x.config.alertOnFail)}function d(e){return e.message||e.description||String(e)}function f(){if(D&&!x.initialized){var t,n=!1,r=!1;e(document,"createRange")&&(t=document.createRange(),y(t,N)&&T(t,C)&&(n=!0));var s=i(document);if(s&&"body"==s.nodeName.toLowerCase())if(s&&e(s,"createTextRange")&&o(t=s.createTextRange())&&(r=!0),n||r){x.initialized=!0,x.features={implementsDomRange:n,implementsTextRange:r};var f;for(var u in _)(f=_[u])instanceof h&&f.init(f,x);for(var l=0,g=I.length;l[index:"+n(e)+",length:"+e.childNodes.length+"]["+(e.innerHTML||"[innerHTML not supported]").slice(0,25)+"]"}return e.nodeName}function g(e){this.root=e,this._next=e}function p(e,t){this.node=e,this.offset=t}function m(e){this.code=this[e],this.codeName=e,this.message="DOMException: "+this.codeName}var R="undefined",v=e.util,C=v.getBody;v.areHostMethods(document,["createDocumentFragment","createElement","createTextNode"])||t.fail("document missing a Node creation method"),v.isHostMethod(document,"getElementsByTagName")||t.fail("document missing getElementsByTagName method");var N=document.createElement("div");v.areHostMethods(N,["insertBefore","appendChild","cloneNode"]||!v.areHostObjects(N,["previousSibling","nextSibling","childNodes","parentNode"]))||t.fail("Incomplete Element implementation"),v.isHostProperty(N,"innerHTML")||t.fail("Element is missing innerHTML property");var E=document.createTextNode("test");v.areHostMethods(E,["splitText","deleteData","insertData","appendData","cloneNode"]||!v.areHostObjects(N,["previousSibling","nextSibling","childNodes","parentNode"])||!v.areHostProperties(E,["data"]))||t.fail("Incomplete Text Node implementation");var S=function(e,t){for(var n=e.length;n--;)if(e[n]===t)return!0;return!1},y=!1;!function(){var t=document.createElement("b");t.innerHTML="1";var n=t.firstChild;t.innerHTML="
",y=l(n),e.features.crashyTextNodes=y}();var w;typeof window.getComputedStyle!=R?w=function(e,t){return d(e).getComputedStyle(e,null)[t]}:typeof document.documentElement.currentStyle!=R?w=function(e,t){return e.currentStyle?e.currentStyle[t]:""}:t.fail("No means of obtaining computed style properties found"),g.prototype={_current:null,hasNext:function(){return!!this._next},next:function(){var e,t,n=this._current=this._next;if(this._current)if(e=n.firstChild)this._next=e;else{for(t=null;n!==this.root&&!(t=n.nextSibling);)n=n.parentNode;this._next=t}return this._current},detach:function(){this._current=this._next=this.root=null}},p.prototype={equals:function(e){return!!e&&this.node===e.node&&this.offset==e.offset},inspect:function(){return"[DomPosition("+h(this.node)+":"+this.offset+")]"},toString:function(){return this.inspect()}},(m.prototype={INDEX_SIZE_ERR:1,HIERARCHY_REQUEST_ERR:3,WRONG_DOCUMENT_ERR:4,NO_MODIFICATION_ALLOWED_ERR:7,NOT_FOUND_ERR:8,NOT_SUPPORTED_ERR:9,INVALID_STATE_ERR:11,INVALID_NODE_TYPE_ERR:24}).toString=function(){return this.message},e.dom={arrayContains:S,isHtmlNamespace:function(e){var t;return typeof e.namespaceURI==R||null===(t=e.namespaceURI)||"http://www.w3.org/1999/xhtml"==t},parentElement:function(e){var t=e.parentNode;return 1==t.nodeType?t:null},getNodeIndex:n,getNodeLength:function(e){switch(e.nodeType){case 7:case 10:return 0;case 3:case 8:return e.length;default:return e.childNodes.length}},getCommonAncestor:r,isAncestorOf:o,isOrIsAncestorOf:function(e,t){return o(e,t,!0)},getClosestAncestorIn:i,isCharacterDataNode:a,isTextOrCommentNode:function(e){if(!e)return!1;var t=e.nodeType;return 3==t||8==t},insertAfter:s,splitDataNode:function(e,t,r){var o=e.cloneNode(!1);if(o.deleteData(0,t),e.deleteData(t,e.length-t),s(o,e),r)for(var i,a=0;i=r[a++];)i.node==e&&i.offset>t?(i.node=o,i.offset-=t):i.node==e.parentNode&&i.offset>n(e)&&++i.offset;return o},getDocument:c,getWindow:d,getIframeWindow:function(e){if(typeof e.contentWindow!=R)return e.contentWindow;if(typeof e.contentDocument!=R)return e.contentDocument.defaultView;throw t.createError("getIframeWindow: No Window object found for iframe element")},getIframeDocument:f,getBody:C,isWindow:u,getContentDocument:function(e,t,n){var r;if(e?v.isHostProperty(e,"nodeType")?r=1==e.nodeType&&"iframe"==e.tagName.toLowerCase()?f(e):c(e):u(e)&&(r=e.document):r=document,!r)throw t.createError(n+"(): Parameter must be a Window object or DOM node");return r},getRootContainer:function(e){for(var t;t=e.parentNode;)e=t;return e},comparePoints:function(e,o,a,s){var c,d,f,u,l;if(e==a)return o===s?0:o=t.childNodes.length?t.appendChild(e):t.insertBefore(e,t.childNodes[n]),r}function c(e,t,n){if(T(e),T(t),r(t)!=r(e))throw new L("WRONG_DOCUMENT_ERR");var o=U(e.startContainer,e.startOffset,t.endContainer,t.endOffset),i=U(e.endContainer,e.endOffset,t.startContainer,t.startOffset);return n?o<=0&&i>=0:o<0&&i>0}function d(e){for(var t,n,o,i=r(e.range).createDocumentFragment();n=e.next();){if(t=e.isPartiallySelectedSubtree(),n=n.cloneNode(!t),t&&(o=e.getSubtreeIterator(),n.appendChild(d(o)),o.detach()),10==n.nodeType)throw new L("HIERARCHY_REQUEST_ERR");i.appendChild(n)}return i}function f(e,t,n){var r,o;n=n||{stop:!1};for(var i,a;i=e.next();)if(e.isPartiallySelectedSubtree()){if(!1===t(i))return void(n.stop=!0);if(a=e.getSubtreeIterator(),f(a,t,n),a.detach(),n.stop)return}else for(r=H.createIterator(i);o=r.next();)if(!1===t(o))return void(n.stop=!0)}function u(e){for(var t;e.next();)e.isPartiallySelectedSubtree()?(u(t=e.getSubtreeIterator()),t.detach()):e.remove()}function l(e){for(var t,n,o=r(e.range).createDocumentFragment();t=e.next();){if(e.isPartiallySelectedSubtree()?(t=t.cloneNode(!1),n=e.getSubtreeIterator(),t.appendChild(l(n)),n.detach()):e.remove(),10==t.nodeType)throw new L("HIERARCHY_REQUEST_ERR");o.appendChild(t)}return o}function h(e,t,n){var r,o=!(!t||!t.length),i=!!n;o&&(r=new RegExp("^("+t.join("|")+")$"));var a=[];return f(new p(e,!1),function(t){if((!o||r.test(t.nodeType))&&(!i||n(t))){var s=e.startContainer;if(t!=s||!W(s)||e.startOffset!=s.length){var c=e.endContainer;t==c&&W(c)&&0==e.endOffset||a.push(t)}}}),a}function g(e){return"["+(void 0===e.getName?"Range":e.getName())+"("+H.inspectNode(e.startContainer)+":"+e.startOffset+", "+H.inspectNode(e.endContainer)+":"+e.endOffset+")]"}function p(e,t){if(this.range=e,this.clonePartiallySelectedTextNodes=t,!e.collapsed){this.sc=e.startContainer,this.so=e.startOffset,this.ec=e.endContainer,this.eo=e.endOffset;var n=e.commonAncestorContainer;this.sc===this.ec&&W(this.sc)?(this.isSingleCharacterDataNode=!0,this._first=this._last=this._next=this.sc):(this._first=this._next=this.sc!==n||W(this.sc)?q(this.sc,n,!0):this.sc.childNodes[this.so],this._last=this.ec!==n||W(this.ec)?q(this.ec,n,!0):this.ec.childNodes[this.eo-1])}}function m(e){return function(t,n){for(var r,o=n?t:t.parentNode;o;){if(r=o.nodeType,Q(e,r))return o;o=o.parentNode}return null}}function R(e,t){if(oe(e,t))throw new L("INVALID_NODE_TYPE_ERR")}function v(e,t){if(!Q(t,e.nodeType))throw new L("INVALID_NODE_TYPE_ERR")}function C(e,t){if(t<0||t>(W(e)?e.length:e.childNodes.length))throw new L("INDEX_SIZE_ERR")}function N(e,t){if(ne(e,!0)!==ne(t,!0))throw new L("WRONG_DOCUMENT_ERR")}function E(e){if(re(e,!0))throw new L("NO_MODIFICATION_ALLOWED_ERR")}function S(e,t){if(!e)throw new L(t)}function y(e,t){return t<=(W(e)?e.length:e.childNodes.length)}function w(e){return!!e.startContainer&&!!e.endContainer&&!(X&&(H.isBrokenNode(e.startContainer)||H.isBrokenNode(e.endContainer)))&&G(e.startContainer)==G(e.endContainer)&&y(e.startContainer,e.startOffset)&&y(e.endContainer,e.endOffset)}function T(e){if(!w(e))throw new Error("Range error: Range is not valid. This usually happens after DOM mutation. Range: ("+e.inspect()+")")}function O(e,t){T(e);var n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset,a=n===o;W(o)&&i>0&&i0&&r=F(n)&&i++,r=0),e.setStartAndEnd(n,r,o,i)}function _(e){T(e);var t=e.commonAncestorContainer.parentNode.cloneNode(!1);return t.appendChild(e.cloneContents()),t.innerHTML}function D(e){e.START_TO_START=de,e.START_TO_END=fe,e.END_TO_END=ue,e.END_TO_START=le,e.NODE_BEFORE=he,e.NODE_AFTER=ge,e.NODE_BEFORE_AND_AFTER=pe,e.NODE_INSIDE=me}function A(e){D(e),D(e.prototype)}function x(e,t){return function(){T(this);var n,r=this.startContainer,o=this.startOffset,i=this.commonAncestorContainer,s=new p(this,!0);r!==i&&(r=(n=a(q(r,i,!0))).node,o=n.offset),f(s,E),s.reset();var c=e(s);return s.detach(),t(this,r,o,r,o),c}}function b(t,r){function o(e,t){return function(n){v(n,$),v(G(n),J);var r=(e?i:a)(n);(t?s:c)(this,r.node,r.offset)}}function s(e,t,n){var o=e.endContainer,i=e.endOffset;t===e.startContainer&&n===e.startOffset||(G(t)==G(o)&&1!=U(t,n,o,i)||(o=t,i=n),r(e,t,n,o,i))}function c(e,t,n){var o=e.startContainer,i=e.startOffset;t===e.endContainer&&n===e.endOffset||(G(t)==G(o)&&-1!=U(t,n,o,i)||(o=t,i=n),r(e,o,i,t,n))}var d=function(){};d.prototype=e.rangePrototype,t.prototype=new d,M.extend(t.prototype,{setStart:function(e,t){R(e,!0),C(e,t),s(this,e,t)},setEnd:function(e,t){R(e,!0),C(e,t),c(this,e,t)},setStartAndEnd:function(){var e=arguments,t=e[0],n=e[1],o=t,i=n;switch(e.length){case 3:i=e[2];break;case 4:o=e[2],i=e[3]}r(this,t,n,o,i)},setBoundary:function(e,t,n){this["set"+(n?"Start":"End")](e,t)},setStartBefore:o(!0,!0),setStartAfter:o(!1,!0),setEndBefore:o(!0,!1),setEndAfter:o(!1,!1),collapse:function(e){T(this),e?r(this,this.startContainer,this.startOffset,this.startContainer,this.startOffset):r(this,this.endContainer,this.endOffset,this.endContainer,this.endOffset)},selectNodeContents:function(e){R(e,!0),r(this,e,0,e,Y(e))},selectNode:function(e){R(e,!1),v(e,$);var t=i(e),n=a(e);r(this,t.node,t.offset,n.node,n.offset)},extractContents:x(l,r),deleteContents:x(u,r),canSurroundContents:function(){T(this),E(this.startContainer),E(this.endContainer);var e=new p(this,!0),t=e._first&&n(e._first,this)||e._last&&n(e._last,this);return e.detach(),!t},splitBoundaries:function(){O(this)},splitBoundariesPreservingPositions:function(e){O(this,e)},normalizeBoundaries:function(){T(this);var e,t=this.startContainer,n=this.startOffset,o=this.endContainer,i=this.endOffset,a=function(e){var t=e.nextSibling;t&&t.nodeType==e.nodeType&&(o=e,i=e.length,e.appendData(t.data),Z(t))},s=function(e){var r=e.previousSibling;if(r&&r.nodeType==e.nodeType){t=e;var a=e.length;if(n=r.length,e.insertData(0,r.data),Z(r),t==o)i+=n,o=t;else if(o==e.parentNode){var s=F(e);i==s?(o=e,i=a):i>s&&i--}}},c=!0;if(W(o))i==o.length?a(o):0==i&&(e=o.previousSibling)&&e.nodeType==o.nodeType&&(i=e.length,t==o&&(c=!1),e.appendData(o.data),Z(o),o=e);else{if(i>0){var d=o.childNodes[i-1];d&&W(d)&&a(d)}c=!this.collapsed}if(c){if(W(t))0==n?s(t):n==t.length&&(e=t.nextSibling)&&e.nodeType==t.nodeType&&(o==e&&(o=t,i+=t.length),t.appendData(e.data),Z(e));else if(nx",ae=3==ie.firstChild.nodeType}catch(e){}e.features.htmlParsingConforms=ae;var se=ae?function(e){var t=this.startContainer,n=z(t);if(!t)throw new L("INVALID_STATE_ERR");var r=null;return 1==t.nodeType?r=t:W(t)&&(r=H.parentElement(t)),r=null===r||"HTML"==r.nodeName&&H.isHtmlNamespace(z(r).documentElement)&&H.isHtmlNamespace(r)?n.createElement("body"):r.cloneNode(!1),r.innerHTML=e,H.fragmentFromNodeChildren(r)}:function(e){var t=r(this).createElement("body");return t.innerHTML=e,H.fragmentFromNodeChildren(t)},ce=["startContainer","startOffset","endContainer","endOffset","collapsed","commonAncestorContainer"],de=0,fe=1,ue=2,le=3,he=0,ge=1,pe=2,me=3;M.extend(e.rangePrototype,{compareBoundaryPoints:function(e,t){T(this),N(this.startContainer,t.startContainer);var n,r,o,i,a=e==le||e==de?"start":"end",s=e==fe||e==de?"start":"end";return n=this[a+"Container"],r=this[a+"Offset"],o=t[s+"Container"],i=t[s+"Offset"],U(n,r,o,i)},insertNode:function(e){if(T(this),v(e,ee),E(this.startContainer),j(e,this.startContainer))throw new L("HIERARCHY_REQUEST_ERR");var t=s(e,this.startContainer,this.startOffset);this.setStartBefore(t)},cloneContents:function(){T(this);var e,t;if(this.collapsed)return r(this).createDocumentFragment();if(this.startContainer===this.endContainer&&W(this.startContainer))return e=this.startContainer.cloneNode(!0),e.data=e.data.slice(this.startOffset,this.endOffset),(t=r(this).createDocumentFragment()).appendChild(e),t;var n=new p(this,!0);return e=d(n),n.detach(),e},canSurroundContents:function(){T(this),E(this.startContainer),E(this.endContainer);var e=new p(this,!0),t=e._first&&n(e._first,this)||e._last&&n(e._last,this);return e.detach(),!t},surroundContents:function(e){if(v(e,te),!this.canSurroundContents())throw new L("INVALID_STATE_ERR");var t=this.extractContents();if(e.hasChildNodes())for(;e.lastChild;)e.removeChild(e.lastChild);s(e,this.startContainer,this.startOffset),e.appendChild(t),this.selectNode(e)},cloneRange:function(){T(this);for(var e,t=new B(r(this)),n=ce.length;n--;)t[e=ce[n]]=this[e];return t},toString:function(){T(this);var e=this.startContainer;if(e===this.endContainer&&W(e))return 3==e.nodeType||4==e.nodeType?e.data.slice(this.startOffset,this.endOffset):"";var t=[],n=new p(this,!0);return f(n,function(e){3!=e.nodeType&&4!=e.nodeType||t.push(e.data)}),n.detach(),t.join("")},compareNode:function(e){T(this);var t=e.parentNode,n=F(e);if(!t)throw new L("NOT_FOUND_ERR");var r=this.comparePoint(t,n),o=this.comparePoint(t,n+1);return r<0?o>0?pe:he:o>0?ge:me},comparePoint:function(e,t){return T(this),S(e,"HIERARCHY_REQUEST_ERR"),N(e,this.startContainer),U(e,t,this.startContainer,this.startOffset)<0?-1:U(e,t,this.endContainer,this.endOffset)>0?1:0},createContextualFragment:se,toHtml:function(){return _(this)},intersectsNode:function(e,t){if(T(this),G(e)!=o(this))return!1;var n=e.parentNode,r=F(e);if(!n)return!0;var i=U(n,r,this.endContainer,this.endOffset),a=U(n,r+1,this.startContainer,this.startOffset);return t?i<=0&&a>=0:i<0&&a>0},isPointInRange:function(e,t){return T(this),S(e,"HIERARCHY_REQUEST_ERR"),N(e,this.startContainer),U(e,t,this.startContainer,this.startOffset)>=0&&U(e,t,this.endContainer,this.endOffset)<=0},intersectsRange:function(e){return c(this,e,!1)},intersectsOrTouchesRange:function(e){return c(this,e,!0)},intersection:function(e){if(this.intersectsRange(e)){var t=U(this.startContainer,this.startOffset,e.startContainer,e.startOffset),n=U(this.endContainer,this.endOffset,e.endContainer,e.endOffset),r=this.cloneRange();return-1==t&&r.setStart(e.startContainer,e.startOffset),1==n&&r.setEnd(e.endContainer,e.endOffset),r}return null},union:function(e){if(this.intersectsOrTouchesRange(e)){var t=this.cloneRange();return-1==U(e.startContainer,e.startOffset,this.startContainer,this.startOffset)&&t.setStart(e.startContainer,e.startOffset),1==U(e.endContainer,e.endOffset,this.endContainer,this.endOffset)&&t.setEnd(e.endContainer,e.endOffset),t}throw new L("Ranges do not intersect")},containsNode:function(e,t){return t?this.intersectsNode(e,!1):this.compareNode(e)==me},containsNodeContents:function(e){return this.comparePoint(e,0)>=0&&this.comparePoint(e,Y(e))<=0},containsRange:function(e){var t=this.intersection(e);return null!==t&&e.equals(t)},containsNodeText:function(e){var t=this.cloneRange();t.selectNode(e);var n=t.getNodes([3]);if(n.length>0){t.setStart(n[0],0);var r=n.pop();return t.setEnd(r,r.length),this.containsRange(t)}return this.containsNodeContents(e)},getNodes:function(e,t){return T(this),h(this,e,t)},getDocument:function(){return r(this)},collapseBefore:function(e){this.setEndBefore(e),this.collapse(!1)},collapseAfter:function(e){this.setStartAfter(e),this.collapse(!0)},getBookmark:function(t){var n=r(this),o=e.createRange(n);t=t||H.getBody(n),o.selectNodeContents(t);var i=this.intersection(o),a=0,s=0;return i&&(o.setEnd(i.startContainer,i.startOffset),s=(a=o.toString().length)+i.toString().length),{start:a,end:s,containerNode:t}},moveToBookmark:function(e){var t=e.containerNode,n=0;this.setStart(t,0),this.collapse(!0);for(var r,o,i,a,s=[t],c=!1,d=!1;!d&&(r=s.pop());)if(3==r.nodeType)o=n+r.length,!c&&e.start>=n&&e.start<=o&&(this.setStart(r,e.start-n),c=!0),c&&e.end>=n&&e.end<=o&&(this.setEnd(r,e.end-n),d=!0),n=o;else for(i=(a=r.childNodes).length;i--;)s.push(a[i])},getName:function(){return"DomRange"},equals:function(e){return B.rangesEqual(this,e)},isValid:function(){return w(this)},inspect:function(){return g(this)},detach:function(){}}),b(B,I),M.extend(B,{rangeProperties:ce,RangeIterator:p,copyComparisonConstants:A,createPrototypeRange:b,inspect:g,toHtml:_,getRangeDocument:r,rangesEqual:function(e,t){return e.startContainer===t.startContainer&&e.startOffset===t.startOffset&&e.endContainer===t.endContainer&&e.endOffset===t.endOffset}}),e.DomRange=B}),x.createCoreModule("WrappedRange",["DomRange"],function(e,t){var n,r,o=e.dom,i=e.util,a=o.DomPosition,s=e.DomRange,c=o.getBody,d=o.getContentDocument,f=o.isCharacterDataNode;if(e.features.implementsDomRange&&function(){function r(e){for(var t,n=u.length;n--;)e[t=u[n]]=e.nativeRange[t];e.collapsed=e.startContainer===e.endContainer&&e.startOffset===e.endOffset}var a,f,u=s.rangeProperties;n=function(e){if(!e)throw t.createError("WrappedRange: Range must be specified");this.nativeRange=e,r(this)},s.createPrototypeRange(n,function(e,t,n,r,o){var i=e.startContainer!==t||e.startOffset!=n,a=e.endContainer!==r||e.endOffset!=o,s=!e.equals(e.nativeRange);(i||a||s)&&(e.setEnd(r,o),e.setStart(t,n))}),(a=n.prototype).selectNode=function(e){this.nativeRange.selectNode(e),r(this)},a.cloneContents=function(){return this.nativeRange.cloneContents()},a.surroundContents=function(e){this.nativeRange.surroundContents(e),r(this)},a.collapse=function(e){this.nativeRange.collapse(e),r(this)},a.cloneRange=function(){return new n(this.nativeRange.cloneRange())},a.refresh=function(){r(this)},a.toString=function(){return this.nativeRange.toString()};var l=document.createTextNode("test");c(document).appendChild(l);var h=document.createRange();h.setStart(l,0),h.setEnd(l,0);try{h.setStart(l,1),a.setStart=function(e,t){this.nativeRange.setStart(e,t),r(this)},a.setEnd=function(e,t){this.nativeRange.setEnd(e,t),r(this)},f=function(e){return function(t){this.nativeRange[e](t),r(this)}}}catch(e){a.setStart=function(e,t){try{this.nativeRange.setStart(e,t)}catch(n){this.nativeRange.setEnd(e,t),this.nativeRange.setStart(e,t)}r(this)},a.setEnd=function(e,t){try{this.nativeRange.setEnd(e,t)}catch(n){this.nativeRange.setStart(e,t),this.nativeRange.setEnd(e,t)}r(this)},f=function(e,t){return function(n){try{this.nativeRange[e](n)}catch(r){this.nativeRange[t](n),this.nativeRange[e](n)}r(this)}}}a.setStartBefore=f("setStartBefore","setEndBefore"),a.setStartAfter=f("setStartAfter","setEndAfter"),a.setEndBefore=f("setEndBefore","setStartBefore"),a.setEndAfter=f("setEndAfter","setStartAfter"),a.selectNodeContents=function(e){this.setStartAndEnd(e,0,o.getNodeLength(e))},h.selectNodeContents(l),h.setEnd(l,3);var g=document.createRange();g.selectNodeContents(l),g.setEnd(l,4),g.setStart(l,2),-1==h.compareBoundaryPoints(h.START_TO_END,g)&&1==h.compareBoundaryPoints(h.END_TO_START,g)?a.compareBoundaryPoints=function(e,t){return t=t.nativeRange||t,e==t.START_TO_END?e=t.END_TO_START:e==t.END_TO_START&&(e=t.START_TO_END),this.nativeRange.compareBoundaryPoints(e,t)}:a.compareBoundaryPoints=function(e,t){return this.nativeRange.compareBoundaryPoints(e,t.nativeRange||t)};var p=document.createElement("div");p.innerHTML="123";var m=p.firstChild,R=c(document);R.appendChild(p),h.setStart(m,1),h.setEnd(m,2),h.deleteContents(),"13"==m.data&&(a.deleteContents=function(){this.nativeRange.deleteContents(),r(this)},a.extractContents=function(){var e=this.nativeRange.extractContents();return r(this),e}),R.removeChild(p),R=null,i.isHostMethod(h,"createContextualFragment")&&(a.createContextualFragment=function(e){return this.nativeRange.createContextualFragment(e)}),c(document).removeChild(l),a.getName=function(){return"WrappedRange"},e.WrappedRange=n,e.createNativeRange=function(e){return(e=d(e,t,"createNativeRange")).createRange()}}(),e.features.implementsTextRange){var u=function(e){var t=e.parentElement(),n=e.duplicate();n.collapse(!0);var r=n.parentElement();(n=e.duplicate()).collapse(!1);var i=n.parentElement(),a=r==i?r:o.getCommonAncestor(r,i);return a==t?a:o.getCommonAncestor(t,a)},l=function(e){return 0==e.compareEndPoints("StartToEnd",e)},h=function(e,t,n,r,i){var s=e.duplicate();s.collapse(n);var c=s.parentElement();if(o.isOrIsAncestorOf(t,c)||(c=t),!c.canHaveHTML){var d=new a(c.parentNode,o.getNodeIndex(c));return{boundaryPosition:d,nodeInfo:{nodeIndex:d.offset,containerElement:d.node}}}var u=o.getDocument(c).createElement("span");u.parentNode&&o.removeNode(u);for(var l,h,g,p,m,R=n?"StartToStart":"StartToEnd",v=i&&i.containerElement==c?i.nodeIndex:0,C=c.childNodes.length,N=C,E=N;;){if(E==C?c.appendChild(u):c.insertBefore(u,c.childNodes[E]),s.moveToElementText(u),0==(l=s.compareEndPoints(R,e))||v==N)break;if(-1==l){if(N==v+1)break;v=E}else N=N==v+1?v:E;E=Math.floor((v+N)/2),c.removeChild(u)}if(m=u.nextSibling,-1==l&&m&&f(m)){s.setEndPoint(n?"EndToStart":"EndToEnd",e);var S;if(/[\r\n]/.test(m.data)){var y=s.duplicate(),w=y.text.replace(/\r\n/g,"\r").length;for(S=y.moveStart("character",w);-1==(l=y.compareEndPoints("StartToEnd",y));)S++,y.moveStart("character",1)}else S=s.text.length;p=new a(m,S)}else h=(r||!n)&&u.previousSibling,p=(g=(r||n)&&u.nextSibling)&&f(g)?new a(g,0):h&&f(h)?new a(h,h.data.length):new a(c,o.getNodeIndex(u));return o.removeNode(u),{boundaryPosition:p,nodeInfo:{nodeIndex:E,containerElement:c}}},g=function(e,t){var n,r,i,a,s=e.offset,d=o.getDocument(e.node),u=c(d).createTextRange(),l=f(e.node);return l?r=(n=e.node).parentNode:(n=s<(a=e.node.childNodes).length?a[s]:null,r=e.node),i=d.createElement("span"),i.innerHTML="&#feff;",n?r.insertBefore(i,n):r.appendChild(i),u.moveToElementText(i),u.collapse(!t),r.removeChild(i),l&&u[t?"moveStart":"moveEnd"]("character",s),u};(r=function(e){this.textRange=e,this.refresh()}).prototype=new s(document),r.prototype.refresh=function(){var e,t,n,r=u(this.textRange);l(this.textRange)?t=e=h(this.textRange,r,!0,!0).boundaryPosition:(e=(n=h(this.textRange,r,!0,!1)).boundaryPosition,t=h(this.textRange,r,!1,!1,n.nodeInfo).boundaryPosition),this.setStart(e.node,e.offset),this.setEnd(t.node,t.offset)},r.prototype.getName=function(){return"WrappedTextRange"},s.copyComparisonConstants(r);var p=function(e){if(e.collapsed)return g(new a(e.startContainer,e.startOffset),!0);var t=g(new a(e.startContainer,e.startOffset),!0),n=g(new a(e.endContainer,e.endOffset),!1),r=c(s.getRangeDocument(e)).createTextRange();return r.setEndPoint("StartToStart",t),r.setEndPoint("EndToEnd",n),r};if(r.rangeToTextRange=p,r.prototype.toTextRange=function(){return p(this)},e.WrappedTextRange=r,!e.features.implementsDomRange||e.config.preferTextRange){var m=Function("return this;")();void 0===m.Range&&(m.Range=r),e.createNativeRange=function(e){return e=d(e,t,"createNativeRange"),c(e).createTextRange()},e.WrappedRange=r}}e.createRange=function(n){return n=d(n,t,"createRange"),new e.WrappedRange(e.createNativeRange(n))},e.createRangyRange=function(e){return e=d(e,t,"createRangyRange"),new s(e)},i.createAliasForDeprecatedMethod(e,"createIframeRange","createRange"),i.createAliasForDeprecatedMethod(e,"createIframeRangyRange","createRangyRange"),e.addShimListener(function(t){var n=t.document;void 0===n.createRange&&(n.createRange=function(){return e.createRange(n)}),n=t=null})}),x.createCoreModule("WrappedSelection",["DomRange","WrappedRange"],function(e,t){function n(e){return"string"==typeof e?/^backward(s)?$/i.test(e):!!e}function r(e,n){if(e){if(T.isWindow(e))return e;if(e instanceof m)return e.win;var r=T.getContentDocument(e,t,n);return T.getWindow(r)}return window}function o(e){return r(e,"getDocSelection").document.selection}function i(e){var t=!1;return e.anchorNode&&(t=1==T.comparePoints(e.anchorNode,e.anchorOffset,e.focusNode,e.focusOffset)),t}function a(e,t,n){var r=n?"end":"start",o=n?"start":"end";e.anchorNode=t[r+"Container"],e.anchorOffset=t[r+"Offset"],e.focusNode=t[o+"Container"],e.focusOffset=t[o+"Offset"]}function s(e){var t=e.nativeSelection;e.anchorNode=t.anchorNode,e.anchorOffset=t.anchorOffset,e.focusNode=t.focusNode,e.focusOffset=t.focusOffset}function c(e){e.anchorNode=e.focusNode=null,e.anchorOffset=e.focusOffset=0,e.rangeCount=0,e.isCollapsed=!0,e._ranges.length=0}function d(t){var n;return t instanceof D?((n=e.createNativeRange(t.getDocument())).setEnd(t.endContainer,t.endOffset),n.setStart(t.startContainer,t.startOffset)):t instanceof A?n=t.nativeRange:P.implementsDomRange&&t instanceof T.getWindow(t.startContainer).Range&&(n=t),n}function f(e){if(!e.length||1!=e[0].nodeType)return!1;for(var t=1,n=e.length;t1,o=[],a=i(t),s=0;s=36)q=!1;else{var l=f.cloneRange();f.setStart(d,0),l.setEnd(d,3),l.setStart(d,2),t.addRange(f),t.addRange(l),q=2==t.rangeCount}}for(T.removeNode(c),t.removeAllRanges(),s=0;s1)C(this,e);else{this.removeAllRanges();for(var t=0,n=e.length;t1?C(this,e):t&&this.addRange(e[0])}}K.getRangeAt=function(e){if(e<0||e>=this.rangeCount)throw new x("INDEX_SIZE_ERR");return this._ranges[e].cloneRange()};var te;if(L)te=function(t){var n;e.isSelectionValid(t.win)?n=t.docSelection.createRange():(n=B(t.win.document).createTextRange()).collapse(!0),"Control"==t.docSelection.type?g(t):l(n)?h(t,n):c(t)};else if(_(W,"getRangeAt")&&"number"==typeof W.rangeCount)te=function(t){if(X&&k&&"Control"==t.docSelection.type)g(t);else if(t._ranges.length=t.rangeCount=t.nativeSelection.rangeCount,t.rangeCount){for(var n=0,r=t.rangeCount;n0)return e.WrappedTextRange.rangeToTextRange(this.getRangeAt(0));throw t.createError("getNativeTextRange: selection contains no range")}),K.getName=function(){return"WrappedSelection"},K.inspect=function(){return S(this)},K.detach=function(){v(this.win,"delete"),R(this)},m.detachAll=function(){v(null,"deleteAll")},m.inspect=S,m.isDirectionBackward=n,e.Selection=m,e.selectionPrototype=K,e.addShimListener(function(e){void 0===e.getSelection&&(e.getSelection=function(){return J(e)}),e=null})});var H=!1,M=function(e){H||(H=!0,!x.initialized&&x.config.autoInitialize&&f())};return D&&("complete"==document.readyState?M():(e(document,"addEventListener")&&document.addEventListener("DOMContentLoaded",M,!1),P(window,"load",M))),x},this); 13 | !function(e,t){"function"==typeof define&&define.amd?define(["./rangy-core"],e):"undefined"!=typeof module&&"object"==typeof exports?module.exports=e(require("rangy")):e(t.rangy)}(function(e){return e.createModule("ClassApplier",["WrappedSelection"],function(e,t){function n(e,t){for(var n in e)if(e.hasOwnProperty(n)&&!1===t(n,e[n]))return!1;return!0}function s(e){return e.replace(/^\s\s*/,"").replace(/\s\s*$/,"")}function r(e,t){return!!e&&new RegExp("(?:^|\\s)"+t+"(?:\\s|$)").test(e)}function o(e,t){return"object"==typeof e.classList?e.classList.contains(t):r("string"==typeof e.className?e.className:e.getAttribute("class"),t)}function a(e,t){if("object"==typeof e.classList)e.classList.add(t);else{var n="string"==typeof e.className,s=n?e.className:e.getAttribute("class");s?r(s,t)||(s+=" "+t):s=t,n?e.className=s:e.setAttribute("class",s)}}function l(e){return"string"==typeof e.className?e.className:e.getAttribute("class")}function u(e){return e&&e.split(/\s+/).sort().join(" ")}function f(e){return u(l(e))}function c(e,t){return f(e)==f(t)}function p(e,t){for(var n=t.split(/\s+/),i=0,r=n.length;ii&&++l,r!=t||o!=n&&o!=n+1||(a=s,l+=i-n),r==t&&o>n+1&&--l,e.node=a,e.offset=l}function m(e,t,n){e.node==t&&e.offset>n&&--e.offset}function g(e,t,n,s){-1==n&&(n=t.childNodes.length);var i=e.parentNode,r=j.getNodeIndex(e);D(s,function(e){h(e,i,r,t,n)}),t.childNodes.length==n?t.appendChild(e):t.insertBefore(e,t.childNodes[n])}function N(e,t){var n=e.parentNode,s=j.getNodeIndex(e);D(t,function(e){m(e,n,s)}),j.removeNode(e)}function v(e,t,n,s,i){for(var r,o=[];r=e.firstChild;)g(r,t,n++,i),o.push(r);return s&&N(e,i),o}function y(e,t){return v(e,e.parentNode,j.getNodeIndex(e),!0,t)}function C(e,t){var n=e.cloneRange();n.selectNodeContents(t);var s=n.intersection(e);return""!=(s?s.toString():"")}function T(e){for(var t,n=e.getNodes([3]),s=0;(t=n[s])&&!C(e,t);)++s;for(var i=n.length-1;(t=n[i])&&!C(e,t);)--i;return n.slice(s,i+1)}function E(e,t){if(e.attributes.length!=t.attributes.length)return!1;for(var n,s,i,r=0,o=e.attributes.length;r0&&t1){var s,i=j.getNodeIndex(n),r=[],o=0;D(t,function(t,a){s=t.parentNode,a>0&&(s.removeChild(t),s.hasChildNodes()||j.removeNode(s),e&&D(e,function(e){e.node==t&&(e.node=n,e.offset+=o),e.node==s&&e.offset>i&&(--e.offset,e.offset==i+1&&adocument.fonts.add(f)) 15 | document.head.insertAdjacentHTML("beforeend",``); 16 | rangy.init(); 17 | let applier = rangy.createClassApplier("rdctd"); 18 | function redact(){ 19 | applier.toggleSelection() 20 | } 21 | GM_registerMenuCommand("Redact", redact) 22 | --------------------------------------------------------------------------------