// ==UserScript== // @name Extended Checkbox Selection // @namespace https://github.com/ // @version 0.9.0 // @description Ctrl+click (Option+click on macOS), or Ctrl/Option+Space, on a checkbox sets every checkbox between it and the last normally-clicked checkbox (in tab order) to the state of that last normally-clicked checkbox. // @author Owen Edwards // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAHE0lEQVR42u2baWxcVxXHf+e+ZRZv46ZpaidKurC2Io0iQHxIIU3FUgL0k1OEoFUipLKoqoirQFXAmQ9BBJQAomIRapqCECRBAioqUIUUJAIURGklRPhAFZGQZOyotmNPZsbzlnv48GzHjrex61bzlLnS1Vgzb97o/O89y/v5XKGhoYI2diUCII1e3eRjQA196qzoewNq0mCiLGpEUSzAun5ty3j4cA7oWvSGlbgrGv6mlK+9R7oEUBVEdO0jZ2/3c50HVO02tVEONPlswbuJinEDjPui1itfLX17/T+aXQSZd+X3oxsfH7o1ir1TJtPRo/XxhkOAI2D8dqJwoiJa23H+Gz1/o++4w4ldcTMKMNdPTyOIaBhw0GQ6e2z11brGoWJDJV58ig11rBLo6MhwYFy/LY7ku6DCHX2ajh0wufXX9ZfaHJUzOO5a4hBEZEklBaqB8v47Mijo70/XyXnEMfqmwUO9Z5vVFeaN1F57LqOot2iQnDFcB0arlnveluHnD3dz7OFu7n17Rsp13DU58s0cBN15VamjjTqsEajWlU1rXL7z8U5iC44BIwKqRHh2iZTpro4pf4DiPdGqCDA7sM/eB6qzP4s18ZCje7pY352UDAd+U+a5f07QnTOU60v8QFGiptsBMw0MIrCTOcA1gueA1aurf7mqPPVQF++6xQfgpy/UOPDcFda0O8SqizrRpgHNBuODj4rjZbHBQh65VBRTdXPGBJUzF77V+2NQWU4l6i5mfBTDmnbh+5/qxhF48MgolbqScQVjYGjc8sTOdh54dw6Av54J+MKxcQr5JSrnyWAbj4/lEQ6YbKdDHICspHgUEEGynfTuHTIXD8tRBk66jbrDgr/oilCuWz5wZ5btb/W5+y0+T36ii8gm4oxULLvemeP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TuGwmSLc2evOYoI3dqyQCTajALZ+NXZfywR/PSnCqjHBZkyDLSbYYoItJthigi0m2GKCLSbYYoItJthigq0+wWbuE3QZULR8yaSbCa68TzD53t5SBZEV15mp7RNUxAhqFbZrWLO4WcMKSFyK+wST0lujGjacmHC8vCcqfhqZ4Ar7BJPrxc3h5ApZcTOOYk9eR32CV6mDcX2J62OnSod6ngKV5cSV1PcJznNzvU76BGeO7avbLp+KPsEWE3w9T40Vxfb2D/7OZAsJExTjTaVGa5UrdZ1mgknEn8MEw0kmePrie9Ztpg+bVFTNh8VaTLBBJjiRGGBVVYltMmfneqtJgeYEaWKCDR2dvfmJ6iYThFkoA4sxMR/X0fDc1wtn0nJ0dulD0OjK/rPTd9wh1Yen52KyxkcRTcsR+v8DNWoQURQbUhAAAAAASUVORK5CYII= // @downloadURL https://raw.githubusercontent.com/OwenEdwards-LevelAccess/ExtendedCheckboxSelection/main/ExtendedCheckboxSelection.js // @updateURL https://raw.githubusercontent.com/OwenEdwards-LevelAccess/ExtendedCheckboxSelection/main/ExtendedCheckboxSelection.js // @match *://*/* // @run-at document-start // @noframes // @grant none // ==/UserScript== /* * MODIFIER KEY: Ctrl on Windows/Linux, Option on macOS. The rest of this comment says "Ctrl" for both. * * BEHAVIOR * - "Checkbox" = or any element with role="checkbox". * - A click (mouse, touch, or keyboard activation) on a checkbox WITHOUT Ctrl records that checkbox and the * state it ended up in as the "initial checkbox". Recording is passive (listeners never stop or alter the * event) and the state is read in a setTimeout(0) after the event has finished dispatching. * - A Ctrl+click (or Ctrl+Space while focused) on a different checkbox, when an initial checkbox is recorded: * the event is cancelled (page handlers never see it), and every enabled checkbox in the tab order between * the initial checkbox (excluded) and the clicked one (included) is put into the recorded state by calling * .click() on each one that is not already in that state, so page click handlers still run. * The initial checkbox is NOT changed by a Ctrl+click, so repeated Ctrl+clicks extend/shrink the range from * the same anchor. Works in either direction (before or after the initial checkbox). * - A Ctrl+click is treated as a normal click (and recorded as a new initial checkbox) when: there is no * recorded initial checkbox; the clicked checkbox IS the initial checkbox; the initial checkbox has been * removed/hidden/made untabbable; the clicked checkbox is not in the tab order; or the recorded state is "mixed". * - Non-checkbox clicks are ignored. Reload / navigation clears the record (so does restoring from bfcache). * * TOGGLE EXTENSION * - After a Ctrl+click (or Ctrl+Space) has applied a range ending at checkbox S, another Ctrl+click on the same * S toggles the whole range, now INCLUDING both the initial checkbox and S: every checkbox in it is set (via * click events) to the opposite of the initial checkbox's current state. Each further Ctrl+click on S toggles * again, flipping back and forth. * - After each toggle, the initial checkbox's resulting state becomes the recorded state, so a later Ctrl+click * on a different checkbox T applies the initial checkbox's current state to the range up to T (T becomes the * new "S"; the first Ctrl+click on T is a normal range application, a repeat on T toggles). * - "Same S" is broken by any normal (non-Ctrl) checkbox click, which also records a new initial checkbox, or * by a Ctrl+click on a different checkbox. Clicks on non-checkbox controls do not affect it. * * TAB ORDER * Based on ANDI's definition of "tabbable" (andi.js :tabbable/:focusable, grab_tabindex): natively focusable * elements (a[href], area[href], button, input not hidden, select, textarea, iframe, summary, contenteditable) * that are not disabled, or any element with a numeric tabindex, excluding tabindex < 0 and elements that are * not visible (display:none / visibility:hidden) or inert. Unlike ANDI (which uses plain DOM order), the order * follows the browser: positive tabindex values ascending first (ties in DOM order), then everything else * in DOM order. * * GEOMETRIC RECTANGLE INTERSECTION FILTER * - In addition to being between the initial and second checkbox in tab order, each intermediate checkbox must * spatially intersect the smallest axis-aligned rectangle (edges parallel to the X and Y axes) that encloses * the clickable areas of both the initial and the second checkbox. If the two checkboxes are in the same row or * column, the rectangle is just that row or column band. * - The clickable area of each checkbox is defined as the union of the checkbox element itself and any associated * visible