code to apply specific style

edited February 2007 in Stylish
what would be the function to programatically apply a specific named style?

what i'm thinking is to have all my ad/element blocking code in each of 3 styles:
- display: none
- replace with a 1px placeholder
- show all blocked elements

i'd then create a custombutton to 3 way toggle those 3 styles. or perhaps this could be a Stylish enhancement? (don't know why this feature is taking so long in AdBlockPlus..)

thoughts or issues?

Comments

  • This may be different in 0.4, but in what I have locally the code would be something like:
    var style = new StylishStyle("the URI in stylish.rdf"); style.enabled = true; style.save();
    I'm going to be releasing a preview of the next version soon, so maybe you'll have to wait for that.
  • You should be able to modify my "Easy Reader" button to do what you want.

    this.quot = function(evt) {
    if(evt.shiftKey) {
    this.showPopup(this);
    return;
    }

    switch(evt.button) {

    case 0:
    var newSS, styles='* { font-family: arial ! important; font-size: 16px ! important; font-weight: bold ! important; background: white ! important; background-image: none ! important; border: none ! important; color: black ! important } :link, :link * { color: black ! important; text-decoration: none ! important } :visited, :visited * { color: black ! important; text-decoration: none ! important }';
    break;

    case 1:
    loadURI("javascript:history.go(0)");
    break;

    case 2:
    var newSS, styles='* { font-family: arial ! important; font-size: 16px ! important; font-weight: bold ! important; background: white ! important; background-image: none ! important; border: none ! important; color: black ! important } :link, :link * { color: black ! important; text-decoration: none ! important } :visited, :visited * { color: black ! important; text-decoration: none ! important } img { visibility: hidden ! important }';
    break;

    }

    if(content.document.createStyleSheet)
    {
    content.document.createStyleSheet("javascript:'"+styles+"'");
    }
    else
    {
    newSS=content.document.createElement('link');
    newSS.rel='stylesheet';
    newSS.href='data:text/css,'+escape(styles);
    content.document.getElementsByTagName("head")[0].appendChild(newSS);
    }
    }
    this.showPopup = function(node) {
    var popup = document.getElementById('custombuttons-contextpopup');
    var x = node.boxObject.x;
    var y = node.boxObject.y + node.boxObject.height;
    document.popupNode = node;
    popup.showPopup(node, x, y, 'popup', null, null);
    }

    this.setAttribute('onclick', 'this.quot(event);');
    this.setAttribute('context', '');
    this.tooltipText = 'L = Images | M = Original | R = No Images';

    }
Sign In or Register to comment.