Welcome guest, is this your first visit? Create Account now to join.
Results 1 to 3 of 3

This is a discussion on Content Script Issues within the Plugins Development section, part of the Chrome Plugins category: facebook.js Code: var port = chrome.extension.connect(); var default_css = "#home_filter_list\n{width: 100% !important; display: block !important; margin: 0px 0px 15px;}\n\n#home_stream\n{width:auto !important;}"; ...


  1. #1
    hexid is offline Junior Member
    Join Date
    Oct 2009
    Posts
    6

    Default Content Script Issues

    facebook.js
    Code:
    var port = chrome.extension.connect();
    var default_css = "#home_filter_list\n{width: 100% !important; display: block !important; margin: 0px 0px 15px;}\n\n#home_stream\n{width:auto !important;}";
    
    function filterPlacement(feedPosition) {
      var filterPosition = port.getElementById(feedPosition).value;
      switch(filterPosition)
      {
      case "top":
        $("#home_filter_list").insertBefore("#pagelet_reqbox");
        var css = default_css;
        break;
      case "bottom":
        $("#home_filter_list").insertAfter("#pagelet_syndicationbox");
        var css = default_css;
        break;
      case "original":
        var css = "#home_filter_list\n{display: block !important;}";
        break;
      default:
        break;
      }
    };
    
    // change style of facebook
    function styleChanges() {
    if (typeof GM_addStyle != "undefined") {
    	GM_addStyle(css);
    } else if (typeof PRO_addStyle != "undefined") {
    	PRO_addStyle(css);
    } else if (typeof addStyle != "undefined") {
    	addStyle(css);
    } else {
    	var heads = document.getElementsByTagName("head");
    	if (heads.length > 0) {
    		var node = document.createElement("style");
    		node.type = "text/css";
    		node.appendChild(document.createTextNode(css));
    		heads[0].appendChild(node); 
    	}
    }
    };
    
    filterPlacement("position");
    styleChanges();
    options.html
    Code:
    <html>
    <head>
    <title>Facebook Options</title>
    <style>
    
    </style>
    
    <script type="text/javascript">
    
    // Saves options to localStorage.
    function save_options() {
      var select = document.getElementById("position");
      var position = select.children[select.selectedIndex].value;
      localStorage["favorite_position"] = position;
    
      // Update status to let user know options were saved.
      var status = document.getElementById("status");
      status.innerHTML = "Options Saved.";
      setTimeout(function() {
        status.innerHTML = "";
      }, 750);
    }
    
    // Restores select box state to saved value from localStorage.
    function restore_options() {
      var favorite = localStorage["favorite_position"];
      if (!favorite) {
        return;
      }
      var select = document.getElementById("position");
      for (var i = 0; i < select.children.length; i++) {
        var child = select.children[i];
        if (child.value == favorite) {
          child.selected = "true";
          break;
        }
      }
    }
    </script>
    </head>
    
    
    <body onload="restore_options()">
    <div id="position_options">
    News Feed Position:
    <select id="position">
     <option disabled="disabled">Left</option>
     <option value="original">Original</option>
     <option disabled="disabled">Right</option>
     <option value="top">Top</option>
     <option value="bottom" selected>Bottom</option>
    </select>
    </div>
    
    <br>
    <button onclick="save_options()">Save</button>
    
    </body>
    </html>
    manifest.json
    Code:
    {
       "content_scripts": [ {
          "exclude_globs": [  ],
          "include_globs": [ "http://facebook.com/*", "https://facebook.com/*", "http://*.facebook.com/*", "https://*.facebook.com/*", "http://facebook.com/*", "https://facebook.com/*/*", "http://*.facebook.com/*/*", "https://*.facebook.com/*/*" ],
          "js": [ "jquery-1.3.2.min.js", "facebook.js" ],
          "css": [ "facebook.css" ],
          "matches": [ "http://*/*", "https://*/*" ]
       } ],
       "description": "Removes all of the ads found on facebook and moves the news menu to the right side to save space",
       "name": "Facebook Cleanup",
       "options_page": "options.html",
       "icons": {
          "128": "images/facebook128.png",
          "16": "images/facebook16.png",
          "32": "images/facebook32.png",
          "48": "images/facebook48.png"
       },
       "version": "1.3.0"
    }
    so far i can't see any errors...but i can't figure out why my options page has no effect on the rest of the code...

    I'm also wondering if it would be better to just use jQuery to get the value of the select tag...if so how would i use it

  2. #2
    Skymt is offline Junior Member
    Join Date
    Nov 2009
    Posts
    20

    Default

    Well, I don't see you ever reading the localStorage in the content script.

  3. #3
    PAEz's Avatar
    PAEz is offline Moderator
    Join Date
    Aug 2009
    Location
    Australia
    Posts
    656

    Default

    We got that sorted out elsewhere...
    [New Ext] Better Gmail
    ....please dont post anything about it there, please post in this thread

    Oh and its great to see someone helping with scripts... and I like yours, sorry Im a dialup user and dont use that sorta thing so cant test it.

Similar Threads

  1. Page Save issues
    By bhavtosh in forum Chrome Troubleshooting
    Replies: 8
    Last Post: 05-01-2010, 08:03 PM
  2. Stuck with content script...
    By rohit in forum Plugins Development
    Replies: 1
    Last Post: 12-15-2009, 03:19 PM
  3. Browser issues
    By Balachandar in forum Bugs and Vulnerabilities
    Replies: 2
    Last Post: 11-17-2009, 03:39 PM
  4. PNG transparency issues in a crx theme
    By mr.upside-down in forum Themes Development
    Replies: 1
    Last Post: 07-07-2009, 10:17 PM
  5. content script problem..
    By Gaurang033 in forum Chrome Plugins
    Replies: 0
    Last Post: 06-01-2009, 10:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •