Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    New Coder
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Automatically changing variables

    Hello,

    I am trying to create a plugin for Google Chrome that substitutes certain words for others. I want to store the words in variables, for example have "x" as a word and "X" as it's substitute. I also want to create an options page where a user can put in new words. My problem is that I don't know how to get the options page to automatically advance to the next variable if the one it is trying to use is already full. Does anybody know how I would go abut doing this? (I am using JavaScript.) Or is there are better way?

    Thanks, fill1890

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Quote Originally Posted by fill1890 View Post
    Hello,

    I am trying to create a plugin for Google Chrome that substitutes certain words for others. I want to store the words in variables, for example have "x" as a word and "X" as it's substitute. I also want to create an options page where a user can put in new words. My problem is that I don't know how to get the options page to automatically advance to the next variable if the one it is trying to use is already full. Does anybody know how I would go abut doing this? (I am using JavaScript.) Or is there are better way?

    Thanks, fill1890
    Do you realise that any such additions made by a user will only be visible to that user? So if he wants ro replace "cat" by"dog" why does he not just type "dog" to start with?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New Coder
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What I mean is that any Google Chrome user could install the plugin, and then it would change certain words on any webpage. I had the idea from http://www.xkcd.com/1031/

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Quote Originally Posted by fill1890 View Post
    What I mean is that any Google Chrome user could install the plugin, and then it would change certain words on any webpage. I had the idea from http://www.xkcd.com/1031/
    I don't think that is possible. Javascript is subject to the Same Origin Policy. Simply stated, the SOP states that JavaScript code running on a web page may not interact with any resource not originating from the same web site.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New Coder
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It is actually a plugin for Google Chrome (Not that I understand a lot of the code, do you want me to post it?). Aside, the main thing I want here is for JavaScript to:

    1) Detect if a variable (e.g. x) is full

    2) If it is not, write to it

    3) If it is, advance to the next variable (e.g. y) and repeat the process

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Quote Originally Posted by fill1890 View Post
    It is actually a plugin for Google Chrome (Not that I understand a lot of the code, do you want me to post it?). Aside, the main thing I want here is for JavaScript to:

    1) Detect if a variable (e.g. x) is full

    2) If it is not, write to it

    3) If it is, advance to the next variable (e.g. y) and repeat the process
    See Post#4.

    To insert code into a page, your extension must have cross-origin permissions for the page.
    Last edited by Philip M; 10-22-2012 at 02:00 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #7
    New Coder
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think we are starting to get into a debate about whether changing text is possible or not. I am not trying to change code. The current plugin is this:

    Before plugin: This is a keyboard.
    After plugin: This is a leopard.
    it changes visible text on a webpage. Not the coding.

    Anyway, What I want to do, irrelevant to what I want to do with it, is

    1) Detect if a variable has a value

    2) If it does not, assign a value determined by a user

    3) If it does, advance to the next variable and repeat the process

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    One more time, what you want is not possible. Changing the value of a variable necessarily involves code to make that change.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,636 Times in 4,598 Posts
    Sorry, Philip, but you are wrong. Chrome supports extensions similar to FireFox's extensions (though implemented differently).

    Look here:
    https://developer.chrome.com/extensions/getstarted.html

    And expecially here:
    https://developer.chrome.com/extensions/overview.html
    Extensions can interact with web pages or servers using content scripts or cross-origin XMLHttpRequests. Extensions can also interact programmatically with browser features such as bookmarks and tabs.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #10
    New Coder
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, Old Pendant, for clearing that up.

    Thank you, Philip M, for explaining. However, couldn't I use JavaScript programming (and variables) in the plugin itself? (Google Chrome can have JavaScript used in plugins.) As far as I know, the only interaction with the webpage itself is changing the text.

  • #11
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Quote Originally Posted by fill1890 View Post
    Thank you, Old Pendant, for clearing that up.

    Thank you, Philip M, for explaining. However, couldn't I use JavaScript programming (and variables) in the plugin itself? (Google Chrome can have JavaScript used in plugins.) As far as I know, the only interaction with the webpage itself is changing the text.
    We seem to be confused as to whether you want to change the value of some Javascript variable or whether you want to change the text as rendered by the page.

    I still say that the first is impossible. It would pose a serious security threat. As for the second, I have no experience. It seems pretty pointless - for example, if you want to replace obscene words by other words the issue arises - why visit such sites in the first place?

    If it helps, you can add to an array by finding the array.length (say len = 10, that is indices 0-9) and then writing the next value to the array[len].
    Last edited by Philip M; 10-26-2012 at 12:47 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,636 Times in 4,598 Posts
    It seems pretty pointless - for example, if you want to replace obscene words by other words the issue arises - why visit such sites in the first place?
    Heh. Did you see the one example? It removes the Google logo and replaces it with an image of a cat.

    Who knows what the point of it is?

    Anyway, what he wants to do--change a word in the rendered text of the page--is clearly possible. He may have misstated how to do it, but it's possible.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #13
    New Coder
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay, I think we agree that I can change rendered text (I hope, because I don't feel like arguing). In response to the message about the security threat, what is your perspective on what I am trying to do? As in, what do you think I am trying to do?

    I don't really understand the part about the arrays. Can you briefly explain or direct me to a website?

  • #14
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Quote Originally Posted by fill1890 View Post
    Okay, I think we agree that I can change rendered text (I hope, because I don't feel like arguing). In response to the message about the security threat, what is your perspective on what I am trying to do? As in, what do you think I am trying to do?

    I don't really understand the part about the arrays. Can you briefly explain or direct me to a website?
    If you do not understand what I said about arrays I really must express doubts doubt whether you have the capability to write a Google plugin in any case, whether or not it would be able to alter words in the rendered text. Do you in fact have any programming experience?

    What do I think you are trying to do? I have no real idea. Perhaps if you explained properly it might become clearer.
    Last edited by Philip M; 10-27-2012 at 12:30 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #15
    New Coder
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, I have programming experience - parts of BASIC, HTML, JSON (only a small amount) and JavaScript. I have nearly finished making a different chrome extension.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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