Copy a code snippet in MS Word using JavaScript? - javascript

I've come across a Word document that includes sections of example code, all of which being preceded by hyperlinks called "Copy" with the following address format:
javascript:CodeSnippet_CopyCode('CodeSnippetContainerCode_538898d8-038f-4f82-9a2d-a558335289ae');
My question is, what in the world is this trying to do, and why isn't it working?
I'm assuming it should be copying the code snippets, but the result of Ctrl+Clicking the links is a security notice (clicked to allow) and then the IE View Downloads window shows up.
Between my not really knowing javascript and all the alphanumeric garbage confusing my efforts to understand the syntax, I can't make heads or tails of this...

This is the Javascript command that is included in some websites such as MSDN to allow you to copy code snippets from the website to the clipboard with one click.
When the original author copied the code to the word document he must of copied the link the links which include that Javascript command as well by a mistake. This type of link has no use in Microsoft Word and it can be removed.

Related

Why there are some files that occasionally replicated themselves in vscode?

In vscode, when I'm working with NodeJS, there are some files that occasionally replicated themselves. Why? and how can I fix it?
I don't know how to solve..
Looking at the names of the files you can see that they differ by an additional number. This is an indication that you copied such a file in place (for example using copy + paste). Try it out. Select one, say main.hbs press Ctrl+C and then Ctrl+V. You will get a new file named main 3.hbs (because main 2.hbs already exists.
So, I assume you have done this by accident before, when you believed the code editor has the focus, but instead the file tree was active.

HTML generated with Sphinx removes the word "module"

A colleague has pointed out to me this peculiar behavior. We use Sphinx to generate the HTML documentation of our project, and whenever we use the word 'module' in our text, this word is removed by the browser.
After some inspection, I have noticed that the word does appear in the source code of the HTML page:
but the rendered result looks like:
where clearly the word 'module' has been removed.
Further inspection on the html source code revealed the following javascript code which seems to be the culprit:
Therefore, I wonder who generates this script? Is it Sphinx or any of its extensions? Is there any workaround to get the word 'module' displayed in the rendered html?
This is the list of Sphinx extensions we have activated:
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.viewcode',
'sphinx.ext.todo',
'sphinx_rtd_theme',
'sphinx.ext.autosectionlabel',
'sphinxcontrib.email',
'sphinxcontrib.bibtex',
'sphinx.ext.graphviz',
'sphinx_git',
]
UPDATE:
I have found the real cause of my problem. For some reason which I ignore, I had a layout.html file in my /source/_templates folder. This file seems to be extending the default one (as in a way explained here), adding the javascript function that removes the word 'module'. Next step will be to find out how did that file get there...
I seem to have come up with a workaround (although not the most satisfying solution)
I thought that this javascript code would work in a single-pass fashion, and therefore, typing 'modulemodule' instead of 'module' would result in the removal of one ocurrence, resulting in a final 'module'. And it has worked!
To make it slightly better, I have created a substitution as .. |module| replace:: modulemodule which I store in another file and include whenever needed. Now, I only need to write my sentence like Hello this is a |module|. (notice the double space between a and |module|)

Jquery image bookmarklet not working in Django

Im working through Django By Example and in one chapter a Jquery bookmarklet is built within a Django app so that a user can easily save jpg images from a website into their user profile area within the Django app.
Im not an experienced JS or Jquery programmer but I did some JS some years back and can read the code however the tutorial does give exact instructions on what to do which I have followed and although I have managed to get the bookmarklet button to appear in my bookmarks bar in Chrome, nothing happens when I click it when browsing a webpage with jpg images.
This is my local Django dashboard where the bookmarklet button is added to the bookmarks bar and this part works fine
and this is what it should look like when clicked on, this is the part where nothing happens for me
these are the relevant js files
https://github.com/davejonesbkk/bookmarks/blob/master/images/templates/bookmarklet_launcher.js
https://github.com/davejonesbkk/bookmarks/blob/master/images/static/js/bookmarklet.js
the only thing I can see that is different with these compared to the files that came with the book is the indentation is a bit off but for some reason the indentation does seem to have changed a bit when I uploaded to Git and they dont look like that locally. Is indentation important in JS?
I followed the same book with the same examples but didn't had any trouble. Make sure your dashboard.html file is referring to the correct javascript file. If nothing works try to add the bookmark manually, you can see how that's done over here http://www.howtogeek.com/189358/beginner-geek-how-to-use-bookmarklets-on-any-device/ it'll sure to work.
And answer to your last question, Indentation is not as important in JavaScript as it's in Python, as python doesn't use any curly braces "{}" or semi-colons ";". But you can write your entire javascript code in a single line and it'll work because your using curly braces everywhere to tell which line of code ends where.
I agree with all the above. In addition, the following:
Error I noticed in the book:
In bookmarklet-launcher.js the js function being called from bookmarklet.js is called myBookmarklet(), however there is no function called this way in bookmarklet.js. So, you may want to use the same name in both js files.
Practically speaking however, the bookmarklet will always work because, not finding a myBookmarklet function in memory, bookmarklet-launcher.js appends the bookmarklet.js script to the body element and, being bookmarklet.js a self-invoking function, its content executed (without the need it to being called). There are some additional interesting technicalities here (the key function in bookmarklet.js is not self invoking but it will anyway be always called because of the script checking whether jQuery is present...) but ok, this is more relevant for those busy with the mentioned book (Django 2 by example).
Check whether bookmarkled, once you click on it, is added to the
current webpage:
2.1. Open devtools (F12 on Chrome) and check e.g. in the html head element whether you find the newly added link element containing the css attribute and/or in the body element whether you find the script element containing the reference to the bookmarklet.js file.
2.2. Alternative: Add an alert message on top of the bookmarklet.js script so that it will be launched if it is correctly loaded. Example:
(function(){
alert('bookmarkled loaded!');
var jquery_version =...
Make sure you're trying to use it on a HTTP site only. Since you're serving from same protocol. HTTPS site would always tell say: There is a problem loadingbyour jquery. That's how I solved mine.
dude.I have solved the problems I met like you.
The most important thing is that noticing the syntax error(without warnings),mainly caused by ignoring blank.
for example, in the line:
jQuery('#bookmarklet .images').append('<img src="'+image_url+'"/>');
between #bookmarklet and .images should lie a blank space,because of jquery syntax rules(meaning to search tag with id of bookmarklet and search tag with class equaling images within result previously).
Another two places worth notice are codes containing #bookmarklet .images a and #bookmarklet #close,requiring blank spaces between filter condition.
That's where I found I made mistaks mainly after studying syntax of jquery.
You'd better compare your codes with codes already loaded up to github by someone to make sure there are no more little errors(such as spelling).

Chrome extension for manipulating webpage by adding an icon next to matched links

Hello i want to write an extension myself and looking for guides/tutorials. I have never created one but i am good with js and html/php.
I need a tutorial/sample code, and here is what i want to do:
when an extension is loaded, i want to add icon next to the google search results (matched links). What it would do is, it will check all the link in a webpage by matching them with a database (php server mysql) and if a match of a domain is found, then it will simply add an icon next to that link (by ofcourse manipulating dom).
Seems like a fairly simple task to do. So if anybody can help me by showing me a correct path or if there is any similar extension already available to learn from, then please advice.
I would be very grateful, thanks!
http://developer.chrome.com/extensions/getstarted.html
Have a browse through this. You'll likely get the hand of it if you're proficient with JS.

Trying to figure out this JavaScript bookmarklet

I`m a JavaScript/programming newbie trying to figure out the new bookmarklet that's been released to help overcome the new NY Times paywall, available at this blog http://euri.ca/2011/03/21/get-around-new-york-times-20-article-limit/
It`s only the following 3 lines of JavaScript....
//Prototype is already installed on NYTimes pages, so I'll use that:
$('overlay').hide();
$('gatewayCreative').hide();
$(document.body).setStyle( { overflow:'scroll' } );
so I thought it would be a not overly complex way to learn about practical uses of JavaScript
When I click on the source code for the actual bookmarklet, it revealed this
NYTClean
The three lines of JavaScript above are located at 'http://toys.euri.ca/nyt.js'
My questions are
a) when he says that Prototype is already installed on NYTimes page, is he referring to the Prototype library, so his code is just altering what they did with the library?
b) in the source code for the bookmarklet, where he does document.getElementsByTagName('head')[0].appendChild(s);})();" does the document refer to the NY Times page that the reader will be on? and 'head' refer to an Element in the NYTimes home page, to which he is appending the child s?
c) is the source code for the bookmarklet wrapped in the link so that appendChild(s) only happens when you click on the link/bookmarklet. Is a bookmark essentially a link which runs code?
d) do you know of a resource that explains how to make the actual bookmarklet which can be dragged from a webpage to the bookmark bar? That drag-to-the-bookmark bar feature is obviously separate from the code it contains, so do you know where I can learn it if I wanted to make my own bookmark to experiment with JavaScript.
a) Yes, he's referring to the Prototype javascript library.
b&c) The way bookmarklets work is by running javascript in the context of a given website by using the "javascript:" protocol. You can run anything you want this way (try typing "javascript:alert('the title is: ' + document.title);" in your address bar and hitting enter. You should get an alert showing you the title of the page you're on. You might consider reading up a bit on how they work on wikipedia.
d) The drag-bookmarklet-to-bar functionality that bookmarklets depend on is actually built in to your web browser. To make an installable bookmarklet that will work on any modern browser, all you have to do is have:
Drag to bookmark bar to install!

Categories

Resources