I'm writing a script using Tampermonkey. I need to somehow get the cookie value (with the session id) from the browser.
            Asked
            
        
        
            Active
            
        
            Viewed 6,131 times
        
    0
            
            
        - 
                    3This is not a duplicate of the question it was marked as a duplicate of. Specifically, this is for Tampermonkey. The other question is for jQuery. – Dan Overlander Sep 12 '17 at 18:55
1 Answers
1
            
            
        You can use COOKIE plugin.
To create a cookie:
$.cookie("example", "foo");
Get a cookie:
$.cookie("example")
Delete a cookie:
$.removeCookie("example");
as community wiki pointed out here.
To use that plugin in Tampermonkey, first you need to load jQuery and then add this plugin:
// @require http://code.jquery.com/jquery-latest.js
// @require https://raw.githubusercontent.com/js-cookie/js-cookie/master/src/js.cookie.js
 
    
    
        Nico_
        
- 1,388
- 17
- 31
 
    
    
        Mert Metin
        
- 411
- 1
- 8
- 21
- 
                    
- 
                    Are you using jQuery? You need jquery first to use that plugin. Also, I would recommend to edit your questions's title. – Mert Metin Dec 04 '16 at 17:21
- 
                    
- 
                    
- 
                    When I want to set that cookie as a var, i just go and use: `var x = Cookies.get("y");`? – Messon Dec 04 '16 at 17:40
- 
                    
- 
                    But I cannot create a session cookie on site i don't own by myself, or can I? – Messon Dec 04 '16 at 17:48
- 
                    
 
    