Welcome to the Power Users community on Codidact!
Power Users is a Q&A site for questions about the usage of computer software and hardware. We are still a small site and would like to grow, so please consider joining our community. We are looking forward to your questions and answers; they are the building blocks of a repository of knowledge we are building together.
Post History
@Canina had the brilliant idea to make my userscript reload the page in case the cookie did not exist previously. Using this idea, my userscript now works like this: Greasemonkey version // ==Us...
Answer
#2: Post edited
- @Canina had the brilliant idea to make my userscript reload the page in case the cookie did not exist previously.
- Using this idea, my userscript now works like this:
- ```
- // ==UserScript==
- // @name test
- // @match *://example.com/*
- // @run-at document-start
- // @grant none
- // ==/UserScript==
- (
- function() {
- 'use strict';
- if (document.cookie.indexOf('uuid') == -1 ) {
- document.cookie = "uuid=xxx";
- location.reload();
- }
- }
- )();
- ```
- @Canina had the brilliant idea to make my userscript reload the page in case the cookie did not exist previously.
- Using this idea, my userscript now works like this:
- ### Greasemonkey version
- ```
- // ==UserScript==
- // @name test
- // @match *://example.com/*
- // @run-at document-start
- // @grant none
- // ==/UserScript==
- (
- function() {
- 'use strict';
- if (document.cookie.indexOf('uuid') == -1 ) {
- document.cookie = "uuid=xxx";
- location.reload();
- }
- }
- )();
- ```
- ### Tampermonkey version
- ```
- // ==UserScript==
- // @name test
- // @description setting cookie
- // @version 1.0
- // @match https://example.com/*
- // @run-at document-start
- // @grant GM_cookie
- // ==/UserScript==
- if (document.cookie.indexOf('uuid') == -1 ) {
- GM.cookie.set({ name: 'uuid', value: 'xxx'}, function(error) {
- console.log(error || 'Quack');
- });
- location.reload();
- }
- ```
#1: Initial revision
@Canina had the brilliant idea to make my userscript reload the page in case the cookie did not exist previously. Using this idea, my userscript now works like this: ``` // ==UserScript== // @name test // @match *://example.com/* // @run-at document-start // @grant none // ==/UserScript== ( function() { 'use strict'; if (document.cookie.indexOf('uuid') == -1 ) { document.cookie = "uuid=xxx"; location.reload(); } } )(); ```