Title: Possible to move or copy existing element in DOM into a different location · uBlockO · Discussion #20 · GitHub
Open Graph Title: Possible to move or copy existing element in DOM into a different location · uBlockO · Discussion #20
X Title: Possible to move or copy existing element in DOM into a different location · uBlockO · Discussion #20
Description: Possible to move or copy existing element in DOM into a different location
Open Graph Description: Hi @uBlock-user ! Does any of your custom scriplets make it possible to copy or move (rather move) a specific element in a DOM tree into a different location in the same DOM tree? I don't have a sp...
X Description: Hi @uBlock-user ! Does any of your custom scriplets make it possible to copy or move (rather move) a specific element in a DOM tree into a different location in the same DOM tree? I don't have ...
Opengraph URL: https://github.com/orgs/uBlockO/discussions/20
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"Possible to move or copy existing element in DOM into a different location","text":"Hi @uBlock-user ! Does any of your custom scriplets make it possible to copy or move (rather move) a specific element in a DOM tree into a different location in the same DOM tree?
\nI don't have a specific site I could link.
","upvoteCount":1,"answerCount":4,"acceptedAnswer":{"@type":"Answer","text":"\nThe point is to be able to place element X before element Y
\n
\n/// insert-child-before.js\n// is.fi##+js(insert-child-before, section.text-positive.bg-header-main, .nav-bar__link-bar)\n (() => {\n\t\tconst selector = '{{1}}';\n\t\tif ( selector === '' || selector === '{{1}}' ) { return; }\n\t const element = '{{2}}';\n\t\tif ( element === '' || element === '{{2}}' ) { return; }\n\t\tconst behavior = '{{3}}';\n\t\tlet timer = undefined;\n\t\tconst insertelem = () => {\n\t\t\ttry {\n\t\t\t\tconst elems = document.querySelectorAll(selector);\n\t\t\t\tconst nodes = document.querySelectorAll(element);\n\t\t\t\tfor (let i = 0; i < elems.length; i++) {\n\t\t\t\t elems[i].before(nodes[i]);\n\t\t\t\t}\t\n\t\t\t} catch { }\n\t \t};\n\t\tconst mutationHandler = mutations => {\n\t\t\tif ( timer !== undefined ) { return; }\n\t\t\tlet skip = true;\n\t\t\tfor ( let i = 0; i < mutations.length && skip; i++ ) {\n\t\t\t const { type, addedNodes, removedNodes } = mutations[i];\n\t\t\t if ( type === 'attributes' ) { skip = false; }\n\t\t\t for ( let j = 0; j < addedNodes.length && skip; j++ ) {\n\t\t\t\tif ( addedNodes[j].nodeType === 1 ) { skip = false; break; }\n\t\t\t }\n\t\t\t for ( let j = 0; j < removedNodes.length && skip; j++ ) {\n\t\t\t\tif ( removedNodes[j].nodeType === 1 ) { skip = false; break; }\n\t\t\t }\n\t\t\t}\n\t\t\tif ( skip ) { return; }\n\t\t\ttimer = self.requestIdleCallback(insertelem, { timeout: 10 });\n\t\t};\n\t\tconst start = ( ) => {\n\t\t\tinsertelem();\n\t\t\tif ( /\\bloop\\b/.test(behavior) === false ) { return; }\n\t\t\tconst observer = new MutationObserver(mutationHandler);\n\t\t\tobserver.observe(document.documentElement, {\n\t\t\t attributes: true,\n\t\t\t childList: true,\n\t\t\t subtree: true,\n\t\t\t});\n\t\t};\n\t\tif ( document.readyState !== 'complete' && /\\bcomplete\\b/.test(behavior) ) {\n\t\t self.addEventListener('load', start, { once: true });\n\t\t } else if ( document.readyState === 'loading' ) {\n\t\t self.addEventListener('DOMContentLoaded', start, { once: true });\n\t\t } else {\n\t\t start();\n\t\t}\n})();\n
\n@peace2000 This works for inserting an element before any child element of a parent element.
","upvoteCount":1,"url":"https://github.com/orgs/uBlockO/discussions/20#discussioncomment-5404543"}}}
| route-pattern | /_view_fragments/Voltron::DiscussionsFragmentsController/show/orgs/:org/:discussion_number/discussion_layout(.:format) |
| route-controller | voltron_discussions_fragments |
| route-action | discussion_layout |
| fetch-nonce | v2:92257248-b80f-8547-66b7-10ffebcc422e |
| current-catalog-service-hash | 9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be |
| request-id | E270:5CE7B:43A264:571B5C:698E81BF |
| html-safe-nonce | 5aa3c03b91329ec3c7a529dd7e822ff24f7743b7088c111102c6cde2e7d63631 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjcwOjVDRTdCOjQzQTI2NDo1NzFCNUM6Njk4RTgxQkYiLCJ2aXNpdG9yX2lkIjoiODA3MTU5NTI5NzQyMjA4MjQ5NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b7741fc5fc17cc68779a329b0102096168a085d23d597fd5b623b54f928e9875 |
| hovercard-subject-tag | discussion:4995918 |
| github-keyboard-shortcuts | repository,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/Voltron::DiscussionsFragmentsController/show/orgs/uBlockO/20/discussion_layout |
| twitter:image | https://opengraph.githubassets.com/d507a5d1a36de5b2de833bc05bce75ad5a1ccc539f856aed2e4c63136d73bff6/orgs/uBlockO/discussions/20 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d507a5d1a36de5b2de833bc05bce75ad5a1ccc539f856aed2e4c63136d73bff6/orgs/uBlockO/discussions/20 |
| og:image:alt | Hi @uBlock-user ! Does any of your custom scriplets make it possible to copy or move (rather move) a specific element in a DOM tree into a different location in the same DOM tree? I don't have a sp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb2828a801ee6b7be618f3ac76fbf55def35bbc30f053a9c41bf90210b8b72ba |
| turbo-cache-control | no-preview |
| octolytics-dimension-user_id | 148974853 |
| octolytics-dimension-user_login | uBlockO |
| octolytics-dimension-repository_id | 89163410 |
| octolytics-dimension-repository_nwo | uBlockO/uBO-Scriptlets |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 89163410 |
| octolytics-dimension-repository_network_root_nwo | uBlockO/uBO-Scriptlets |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f7a12861f7011eecb14bcc4388a767d829a52dfc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width