1

Тема: Управление cookie в imacros

Удаление cookie:

    function cleanCookies(current_url) {
        var cookieManager = Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfaces.nsICookieManager);
            // Add a "." before the URL, as some cookies are stored as .www.domain.com
            current_url = "." + current_url.substring(0);
 
        // alert(current_url);
        var iter = cookieManager.enumerator;
        var cookie_count = 0;
        while (iter.hasMoreElements()) {
            var cookie = iter.getNext();
            if (cookie instanceof Components.interfaces.nsICookie) {
                //alert(current_url + " instanceOf " + cookie.host + current_url.indexOf(cookie.host));
                if (current_url.indexOf(cookie.host) != -1) {    
                    cookieManager.remove(cookie.host, cookie.name, cookie.path, cookie.blocked);
                    cookie_count++;
                }
            }
        }
    }

Получение и установка cookie:

var imJS = {

    get Ci() {
        return Components.interfaces;
    },

    get Cu() {
        return Components.utils;
    },

    setCookie: function setCookie(cookies) {
        this.Cu.import("resource://gre/modules/Services.jsm");

        for (var i = 0; i < cookies.length; i++) {
            Services.cookies.add(cookies[i].host, cookies[i].path,
                cookies[i].name, cookies[i].value, cookies[i].isSecure,
                cookies[i].isHttpOnly, cookies[i].isSession, cookies[i].expiry);
        };
    },

    getCookie: function(domain) {
        this.Cu.import("resource://gre/modules/Services.jsm")
        var services = Services.cookies.getCookiesFromHost(domain);
        var listCookies = [];

        while (services.hasMoreElements()) {
            var cookie = services.getNext().QueryInterface(this.Ci.nsICookie2);
            listCookies.push(cookie);
        };

        return listCookies;
    },
}

var objCookie = imJS.getCookie("softvopros.ru"); // получить куки
imJS.setCookie(objCookie);  // установить куки

Поделиться

2

Re: Управление cookie в imacros

Так же можно выдрать соответствующие коды отсюда https://github.com/Infocatcher/Custom_B … ermissions

Поделиться