Title: Setting cookies? · uBlockO · Discussion #21 · GitHub
Open Graph Title: Setting cookies? · uBlockO · Discussion #21
X Title: Setting cookies? · uBlockO · Discussion #21
Description: Setting cookies?
Open Graph Description: Hi @uBlock-user, as you have scriplets to set local items and session items, could you also consider adding a scriplet that allows to set cookies on websites? This could be useful as it'd allow aut...
X Description: Hi @uBlock-user, as you have scriplets to set local items and session items, could you also consider adding a scriplet that allows to set cookies on websites? This could be useful as it'd allow...
Opengraph URL: https://github.com/orgs/uBlockO/discussions/21
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"Setting cookies?","text":"Hi @uBlock-user, as you have scriplets to set local items and session items, could you also consider adding a scriplet that allows to set cookies on websites? This could be useful as it'd allow automatically to force specific settings on websites or restore them if the browser cache has been emptied.
\nOne use case: if you set a cookie on Youtube https://www.youtube.com/ which Name is SOCS and Value is CAESEwgDEgk1MjE4NjcxMTIaAmVuIAEaBgiAl7ihBg, that would allow to skip the GDPR dialog automatically with the setting \"Reject all\".
\n","upvoteCount":2,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"/// setCookie.js\n// example.com##+js(setCookie, SOCS, CAESEwgDEgk1MjE4NjcxMTIaAmVuIAEaBgiAl7ihBg)\nfunction( \n\tcName = '', \n\tcValue = '',\n\texpTime = '',\n\tbehavior = '' \n) {\n\tlet timer = undefined;\n\tif ( cName === '' ) { return; }\n\tif ( expTime === '' ) { expTime = '1'; }\n\tif ( cValue === '' ) { cValue = '\"\"'; }\t\n\tconst setCookie = () => {\n\t\ttry {\n\t\t\tconst cookies = document.cookie;\n\t\t\tif ( !cookies.includes(cName) || !cookies.includes(cValue) ) {\n\t\t \t\tconst date = new Date();\n\t\t\t\tdate.setTime(date.getTime() + (expTime * 24 * 60 * 60 * 1000));\n\t\t\t\tconst expires = \"expires=\" + date.toUTCString();\n\t\t\t\tdocument.cookie = cName + \"=\" + cValue + \"; \" + expires + \"; path=/\";\n\t\t\t} else { \n\t\t\t\treturn; \n\t\t\t}\t\n\t\t} catch { }\n\t};\n\tconst mutationHandler = mutations => {\n\tif ( timer !== undefined ) { return; }\n\tlet skip = true;\n\tfor ( let i = 0; i < mutations.length && skip; i++ ) {\n\t const { type, addedNodes, removedNodes } = mutations[i];\n\t if ( type === 'attributes' ) { skip = false; }\n\t for ( let j = 0; j < addedNodes.length && skip; j++ ) {\n\t\tif ( addedNodes[j].nodeType === 1 ) { skip = false; break; }\n\t }\n\t for ( let j = 0; j < removedNodes.length && skip; j++ ) {\n\t\tif ( removedNodes[j].nodeType === 1 ) { skip = false; break; }\n\t }\n\t}\n\tif ( skip ) { return; }\n\ttimer = self.requestIdleCallback(setCookie, { timeout: 10 });\n\t};\n\tconst start = ( ) => {\n\tsetCookie();\n\tif ( /\\bloop\\b/.test(behavior) === false ) { return; }\n\tconst observer = new MutationObserver(mutationHandler);\n\tobserver.observe(document.documentElement, {\n\t attributes: true,\n\t childList: true,\n\t subtree: true,\n\t});\n\t};\n\tif ( document.readyState !== 'complete' && /\\bcomplete\\b/.test(behavior) ) {\n\tself.addEventListener('load', start, { once: true });\n\t} else if ( document.readyState !== 'loading' || /\\basap\\b/.test(behavior) ) {\n\tstart(); \n\t} else {\n\tself.addEventListener('DOMContentLoaded', start, { once: true });\n\t}\t\n}\n \n
\n","upvoteCount":1,"url":"https://github.com/orgs/uBlockO/discussions/21#discussioncomment-5551256"}}}
| route-pattern | /orgs/:org/discussions/:number(.:format) |
| route-controller | discussions |
| route-action | show |
| fetch-nonce | v2:8f92fc0f-6115-7c36-45b6-3238fc5894e9 |
| current-catalog-service-hash | 9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be |
| request-id | 9EA4:115553:D3555:114DB6:698E9E19 |
| html-safe-nonce | 634bf6e221bb1048adbf8cfaaa189181815f2adb840eae2031182784828e4944 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RUE0OjExNTU1MzpEMzU1NToxMTREQjY6Njk4RTlFMTkiLCJ2aXNpdG9yX2lkIjoiOTA4ODU0NDA3NzM3NzM0NzA5NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f78c1dbf77f49bf822ee1f3233b6ac12d1e437fbdd621e49d7a3d29786b2bf93 |
| hovercard-subject-tag | discussion:5052981 |
| 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/orgs/uBlockO/discussions/21 |
| twitter:image | https://opengraph.githubassets.com/e0757ec7ac2b19ed38bb557714cf173a5d73b3d65d9e7bd681f60b77bbe29a05/orgs/uBlockO/discussions/21 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e0757ec7ac2b19ed38bb557714cf173a5d73b3d65d9e7bd681f60b77bbe29a05/orgs/uBlockO/discussions/21 |
| og:image:alt | Hi @uBlock-user, as you have scriplets to set local items and session items, could you also consider adding a scriplet that allows to set cookies on websites? This could be useful as it'd allow aut... |
| 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 | e6b91a7e6e46287d26887e3fb7a4161657bab8f7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width