How to read and modify the contents of any page? - google-chrome-extension

This is my first app so please pardon my lack of knowledge. As a demo app i would like to achieve the following things :
Stage 1 :
1 Read the contents of a page
2 Look for a regex match in the contents of that page
3 Replace them with something else
Stage 2 :
1 On submitting () text to a web page
2 Read the text that's about to get submitted
3 Look for a regex and replace it .
Could some one point in the direction of a similar app or make a small guide ? Any help is appreciated .

first of all, you need to insert a Content Script, the only way to access the page's content.
http://code.google.com/chrome/extensions/content_scripts.html
You can make a content script only extension to begin, but for more advanced extensions you should read about programmatic injection.
http://code.google.com/chrome/extensions/content_scripts.html#pi
From a content script you can access the page's DOM, and add listener to events in the usual way. For example, you can use document.getElementById() or element.addListener() .
There are many ways to look for a regexp, it depends the way you want to search the page, for example yo can use
document.body.innerHTML.replace(...);
Rob W gave you a nice hint to intercept submitting text with
chrome.webRequest

Related

Grav - Parse URL

I want to define a new template called "product".
This template calls an external service and retrieves the information about that specific product. That is easily done with a custom plugin that access the product information. Information on how to do that has been found here.
However, I would like that the URL of the page would be something like:
/product/<id>/<seo-friendly-description>
So I can retrieve in the Twig template both <id> and <seo-friendly-description> which will be used later to retrieve the specific product information.
I have tried to find something that could help in the documentation, without success. Could someone either point me to the right doc section or highlight the basic steps that shall be achieved so I can start solving this issue?
Just in case it helps, I am trying to find something similar to how bottle or other web frameworks work:
#route('/hello/<name>')
def greet(name):
return 'Hello ' + name
I've been building a family recipebook into my own website and I've been working through a similar problem. I haven't quite worked out all the kinks, but my solution is mostly working if you want to checkout my github repo.
In short, you need the plugin to watch what the active route is. If the route matches, you then create the page and populate it using your plugin data.
I haven't quite figured out how to get the active page to highlight in the navigation menu for generated pages, but you might still find this solution helpful.

NodeJS Jade (Pug) inline link in dynamic text

I have this NodeJS application, that uses Jade as template language. On one particular page, one text block is retrieved from the server, which reads the text from database.
The problem is, the returned text might contain line-breaks and links, and an operator might change this text at any time. How do I make these elements display correctly?
Most answers suggest using a new line:
p
| this is the start of the para
a(href='http://example.com') a link
| and this is the rest of the paragraph
But I cannot do this, since I cannot know when the a element appears. I've solved how to get newline correct, by this trick:
p
each l in line.description.split(/\n/)
= l
br
But I cannot seem to solve how to get links to render correctly. Does anyone know?
Edit:
I am open to any kind of format for links in the database, whatever would solve the issue. For example, say database contains the following text:
Hello!
We would like you to visit [a("http://www.google.com")Google]
Then we would like that to output text that looks like this:
Hello!
We would like you to visit Google
Looks like what you're looking for is unescaped string interpolation. The link does not work in the output because Pug automatically escapes it. Wrap the content you want to insert with !{} and it should stop breaking links. (Disclaimer: Make sure you don't leave user input unescaped - this only is a viable option if you know for sure the content of your DB does not have unwanted HTML/JS code in it.)
See this CodePen for illustration.
With this approach, you would need to use standard HTML tags (<a>) in your DB text. If you don't want that, you could have a look at Pug filters such as markdown-it (you will still need to un-escape the compilation output of that filter).

how to modify _xspAppSearchSubmit on Application Layout Xpages

Im trying to modify search parameter in Application Layout Search, to accept dot(.) as literal part of search item for filtering a view..
for example...
"Mr. Smith" will not show up in the view, but
"Mr.Smith" will..
digging deeper with google debugger, I found the function _xspAppSearchSubmit where I can simply change the code encodeURIComponent(val) into encodeURIComponent(val.replace(/s+\.s+/g,'')
which worked when i tested on console. The s+ to remove spaces, \. to keep the dot as literal.
BUT somehow, I cannot find this function in the ApplicationLayout1 custom control, and listed only one event - onItemClick.
Is it possible to add an "onChange" event?
There's an option and optionParam property there but not sure how to apply this.
Im a newbie with xpage and this control, can someone help me work around this, I've checked other sites about this but doesn't explain this kind of issue. I've also checked encodeURIComponent functionality, but it still interprets dot as command. I also learned this dot works like * wildcard.
the Application Layout is ccBaseUI from "One UI", and setup Basic Application Configuration.
code snippet capture

Drupal 7 Programmatically Replace Field in Views

I have a question regarding Drupal 7 and the Views API.
I'm writing a module that replaces specific text in views. Essentially what I'm trying to do is scan text in a view (or page for that matter). Let's say the view has [special button] will be replaced with
l(t('button'),'mypage',array('query',array('page'=>$node->nid)));
Or whatever. Please understand this is pseudo code.
I've took a look at hook_view(), hook_node_view() (http://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_view/7) and neither of them seem to work for me.
I've also looked at http://drupal.org/node/1510828 but that didn't seem to help me out.
Have you tried selecting 'rewrite the output of this field' on the field/s ?
Or alternatively Views PHP should be able to do what you want.

Any way in Expression Engine to simulate Wordpress' shortcode functionality?

I'm relatively new to Expression Engine, and as I'm learning it I am seeing some stuff missing that WordPress has had for a while. A big one for me is shortcodes, since I will use these to allow CMS users to place more complex content in place with their other content.
I'm not seeing any real equivalent to this in EE, apart from a forthcoming plugin that's in private beta.
As an initial test I'm attempting to fake shortcodes by using delimited strings (e.g. #foo#) in the content field, then using a regex to pull those out and pass them to a function that can retrieve the content out of EE's database.
This brings me to a second question, which is that in looking at EE's API docs, there doesn't appear to be a simple means of retrieving the channel entries programmatically (thinking of something akin to WP's built-in get_posts function).
So my questions are:
a) Can this be done?
b) If so, is my method of approaching it reasonable? Or is there something stupidly obvious I'm missing in my approach?
To reiterate, my main objective here is to have some means of allowing people managing content to drop a code in place in their content that will be replaced with channel content.
Thanks for any advice or help you can give me.
Here's a simple example of the functionality you're looking for.
1) Start by installing Low Replace.
2) Create two Global Variables called gv_hello and gv_goodbye with the values "Hello" and "Goodbye" respectively.
3) Put this text into the body of an entry:
[say_hello]
Nice to see you.
[say_goodbye]
4) Put this into your template, wrapping the Low Replace tag around your body field.
{exp:low_replace
find="[say_hello]|[say_goodbye]"
replace="{gv_hello}|{gv_goodbye}"
multiple="yes"
}
{body}
{/exp:low_replace}
5) It should output this into your browser:
Hello
Nice to see you.
Goodbye
Obviously, this is a really simple example. You can put full blown HTML into your global variable. For example, we've used that to render a complex, interactive graphic that isn't editable but can be easily dropped into a page by any editor.
Unfortunately, due to parse order issues, EE tags won't work inside Global Variables. If you need EE tags in your short code output, you'll need to use Low Variables addon instead of Global Variables.
Continued from the comment:
Do you have examples of the kind of shortcodes you want to support/include? Because i have doubts if controlling the page-layout from a text-field or wysiwyg-field is the way to go.
If you want editors to be able to adjust layout or show/hide extra parts on the page, giving them access to some extra fields in the channel, is (imo) much more manageable and future-proof. For instance some selectfields, a relationship (or playa) field, or a matrix, to let them choose which parts to include/exclude on a page, or which entry from another channel to pull content from.
As said in the comment: i totally understand if you want to replace some #foo# tags with images or data from another field (see other answers: nsm-transplant, low_replace). But, giving an editor access to shortcodes and picking them out, is like writing a template-engine to generate ee-template code for the ee-template-engine.
Using some custom fields to let editors pick and choose parts to embed is, i think, much more manageable.
That being said, you could make a plugin to parse the shortcodes from a textareas content, and then program a lot, to fetch data from other modules you want to support. For channel entries you could build out of the channel data library by objectiveHTML. https://github.com/objectivehtml/Channel-Data
I hear you, I too miss shortcodes from WP -- though the reason they work so easily there is the ubiquity of the_content(). With the great flexibility of EE comes fewer blanket solutions.
I'd suggest looking at NSM Transplant. It should fit the bill for you.
There is also a plugin called Shortcode, which you can find here at
Devot-ee
A quote from the page:
Shortcode aims to allow for more dynamic use of content by authors and
editors, allowing for injection of reusable bits of content or even
whole pieces of functionality into any field in EE

Resources