Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthoraacar
    • CommentTimeFeb 1st 2011
     permalink
    I have the following greasemonkey script which replaces:

    <TR><TD

    with

    <TR><TD style="background-color:red;margin:-10px;padding:-10px;overflow:hidden;"><form name="myform"><input type="hidden" name="phpMyAdmin" value="4594f30712f4fabaff6997416810f3f2" /><input type="checkbox" name="mybox"></form></TD><TD


    in the page source.

    And

    puts a checkbox for each match. However, this script does not keep the latest state of the checkbox when you go back and forth in the browser.


    My question is: How can I make it on the client side using JS in greasemonkey without logging information into a database?

    Here is my script that creates the checkbox in the desired location on the page:

    // ==UserScript==
    // @name xxx1
    // @namespace xxx2
    // @include some valid web site
    function do_checkbox_script() {

    do_modify_html_it(
    window.document,
    document.evaluate(
    '/HTML[1]/BODY[1]/TABLE[1]',
    document,
    null,
    XPathResult.FIRST_ORDERED_NODE_TYPE,
    null).singleNodeValue,/<TR><TD/gi,
    '<TR><TD style="background-color:red;margin:-10px;padding:-10px;overflow:hidden;"><form name="myform"><input type="hidden" name="phpMyAdmin" value="4594f30712f4fabaff6997416810f3f2" /><input type="checkbox" name="myCheckbox" onclick="createCookie(myCookie, false, 365)"></form></TD><TD',
    null);


    do_modifyAlignment_html_it(
    window.document,
    document.evaluate(
    '/HTML[1]/BODY[1]/TABLE[1]',
    document,
    null,
    XPathResult.FIRST_ORDERED_NODE_TYPE,
    null).singleNodeValue,/<TH>Job<\/TH>/gi,
    '<TH></TH><TH>Job</TH>',
    null);

    }; // Ends do_checkbox_script


    window.addEventListener("load", function() { do_checkbox_script() }, false);
    //

    function do_modify_html_it(doc, element, match_re, replace_string) {
    match_re = new RegExp(match_re);
    if (element.innerHTML) {
    element.innerHTML = element.innerHTML.replace(match_re, replace_string);
    };
    };

    window.addEventListener("load", function() { do_modify_html_it() }, false);

    function createCookie(name, value, days) {
    var expires = "";
    var date;
    if (days) {
    date = new Date();
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    expires = "; expires=" + date.toGMTString();
    }
    document.cookie = name + "=" + value + expires + "; path=/";
    }

    function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    var c;
    for (var i = 0; i < ca.length; i++) {
    c = ca[i];
    while (c.charAt(0) === ' ') {
    c = c.substring(1, c.length);
    }
    if (c.indexOf(nameEQ) === 0) {
    return c.substring(nameEQ.length, c.length);
    }
    }
    return null;
    }

    //.user.js


    Thanks,

    Artug
Add your comments
    Username Password
  • Format comments as (Help)