When copying automatically add URL - html

I have seen on few websites that when you copy some text from there, and paste anywhere, it will add the URL of the page from where I copied the text.
For example:
This is text I copied.
and when I paste, I get:
This is text I copied.
Read more: http://example.com/abc/def
I'm just curious to know how this is done? How to add additional text in the copied text?
Example: Check this question (or any other) on answers.com. Copy the question text and paste. Tested with Firefox latest version.

There are many online tools which provide this and other website/blog management utilities. Answer.com is also using one such service named tynt. Open the link, scroll down to the bottom and you can see answer.com in featured clients ;).
For more information.

Zeroclipboard should help you modify the clipboard content. It's a flash movie that is hidden in the browser and exposes a JavaScript API to access the clipboard.
Example.
var clip = new ZeroClipboard.Client();
clip.addEventListener('complete', function(client, text) {
clip.setText(text + "Read more at www.");
});

Related

Appending a url using a bookmarklet and clipboard item

I want to append text that has been copied to the clipboard to the end of a url when a bookmarklet is used.
i.e. highlight text, copy and click the bookmarklet and I go to a url with the copied text at the end.
Any help would be great.
I have this code but it works with highlighting text on a browser page. I want to read from the clipboard.
javascript:window.location.href="http://www.mybaseurl.com/"+window.getSelection()
I also have this code that is a little closer to what I need.
It prompts for input and goes to a url with the input at the end of a url
javascript:(function(){var val= prompt("Enter #","");if (val)location="https://www.test.com/send?phone="+escape(val);})()
after a bit of fooling around this is what worked for me, do note however that it will be asking for clipboard permissions, so it's somewhat limited in that regard.
javascript:navigator.clipboard.readText().then((clipText) => location="http://www.mybaseurl.com/"+escape(clipText))

Swift - MacOS NSPasteboard - simultaneously support HTML and plain strings

I have a use-case where I want my application to store clipboard data and later allow the user to paste it out.
The thing is - I want to both support HTML-styled text (while maintaining its styling) and also support simple plain-text.
What I have so far is:
Pasteboard variable setup
let pasteboard = NSPasteboard.general
pasteboard.declareTypes([.html, .string], owner: nil)
Storing user's clipboard data
let copiedString = pasteboard.string(forType: .html) ?? pasteboard.string(forType: .string) {
If, for example, a user copies text from the browser, this method maintains the entire HTML.Alternatively, if text is being copied from applications that don't support HTML (such as XCode, Notes, etc), `copiedString` will simply hold the plain text.
Later down the line - pushing contents back to clipboard
pasteboard.setString(copiedString, forType: .html)
My problem is, when I try to paste the content pushed into my clipboard; it only works in applications that actually support HTML-formatted text, such as Chrome / Microsoft Word.
When I try to paste the content into XCode for example, it simply doesn't spit out anything.
Ideally, I want my clipboard to adjust itself according to the application I'm on - paste the text as HTML if supported by the application, otherwise - paste the plain text.
How can I implement such behavior?
Thanks!

YouTube subscribe button code doesn't work

When I customize the YouTube subscribe button code to reflect my channel, the code changes when I try pasting it into the html space in my wordpress blog.
I try copying this:
<script src="https://apis.google.com/js/platform.js"></script>
<div class="g-ytsubscribe" data-channel="TheAtheistsNextDoor" data-layout="full" data-count="default"></div>
and then when it pastes, it always ends up like this:
<div class="g-ytsubscribe"></div>
I should add that when I copy the html from the code box, it changes the preview from what is correct, to: These aren't the XSS vulnerabilities you're looking for.
How is the simple act of copying the code changing it somehow? Why would it paste as something completely different?
Hey #Bridget Ludwa O'Hanlon, I am not too familiar with Wordpress. With that being said to answer your first question, not sure why the code is changing may be the client your using or you. To using the subscribe button here is the code***Note I am using my channel as you did not say yours***:
Default:
<script src="https://apis.google.com/js/platform.js"></script>
Full:
<script src="https://apis.google.com/js/platform.js"></script>
There are many different combinations you can do i would highly suggest checking out the first source posted below as google is a programmers friend (remember this) Thankfully google helps you out by telling you how to create this button and even gives you a generator for it.
sources: https://developers.google.com/youtube/youtube_subscribe_button
sources:http://www.wpbeginner.com/wp-tutorials/how-to-add-youtube-subscribe-button-in-wordpress/
Wordpress has this thing where it modifies you code if you jump between visual and text tab. But a rule of thumb, goto text tab -> paste your code and click the update button. Dont go to the visual tab unless the code is pasted and updated.
OR
You can try using. You can try replacing the existing editor with https://wordpress.org/plugins/foliopress-wysiwyg/

Is there a way to allow users to copy text from a website, and the text be unformatted?

Pretty much just the question. I have a client that is requesting a negative design with nearly white text all over the webpage, but testers are saying that it's annoying to copy and paste from the website as everything shows up as white text when copying into Word or the like.
Is there a way to either preemptively remove formatting when a user tries to copy text from the website? Or is there a way to hijack what actually gets put on the clipboard?
Ctrl + alt + v or ctrl +shift + v should paste what's on your clipboard as unformatted text. Very handy for copying code samples to word docs. This should also work on Mac if you substitute cmd for Ctrl
Using code from both here Javascript: Hijack Copy? and here Get the Highlighted/Selected text (thanks #Jacque Goupil) I was able to piece together the following code that strips the formatting from anything copied on the page:
$("body").bind('copy', function(e) {
var newEl = document.createElement("p");
document.body.appendChild(newEl);
if (window.getSelection) {
newEl.innerHTML = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
newEl.innerHTML = document.selection.createRange().text;
}
var selection = document.getSelection();
var range = selection.getRangeAt(0);
selection.selectAllChildren(newEl);
setTimeout(function() {
newEl.parentNode.removeChild(newEl);
selection.removeAllRanges();
selection.addRange(range);
}, 0)
});
What goes in the clipboard by default depends on the browser. Text processors like Microsoft Word usually have options to ignore pasted style, so it shouldn't be an issue if they learn how to use it properly.
If you still want to make life easier for people, you could detect copy events and replace the formated text with raw text. This might help you:
How do I copy to the clipboard in JavaScript?
Get the Highlighted/Selected text
In Word you've got the option to 'Paste as plain text' (or 'Paste without formatting', not sure of the exact name in English). That way, you can easily paste text from any website without markup.
I don't think it should be the responsibility of the website to implement a 'copy without markup'.
Other trick: paste text with markup in Notepad first. Then select it in Notepad and copy again. The clipboard now contains only plain text.
Of course it's hard to educate the users, but unless there is a very good reason why people would be copying texts from the website, I wouldn't make a custom implementation for it. Those implementations, especially when you override default behaviour (capture Ctrl+C), will probably not work well or at least the same in every browser, and they are just a fix for your website, not everyone else's. Also, such a feature might annoy other users who do know how to handle text with mark-up. So I think it's better to let the users figure out themselves.
As for hijacking the clipboard, if you copy HTML, the browser actually copies the content in multiple formats, like HTML, RTF and plain text. If you had the means, you could simply remove the HTML and RTF version from the clipboard and let the plain text version remain. But I'm pretty sure you don't have that much control over the clipboard from the browser.

HTML Input Droppable + Libre Office

I've a droppable input.
1- When i drag drop a html text, the drop works...
2- When i drag drop a gedit (bloc note linux), the drop works
3- But When i want to drop a selected text from LibreOffice Writer or
Calc, it don't works...
I've created a fiddle if someone can help me... : http://jsfiddle.net/CnwvC/
with code
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<input id='inputid' type='text' value="snif">
<p>html blabla to test to drop </p>
Instead of gedit, the LibreOffice text content is not plain text. This could be one of the reasons that it doesn't allow you drag and drop its content to your input box.
One interesting fact is that if you drag and drop a content from a webpage to you document on Writer you'll get the HTML content of the page (all the tags), but if you do the same in Google Chrome, you will get the rich content (like colour, formatting, and so on). This was reported by other folks.
If you try to drag LibreOffice's content to any area on Firefox, it will be same issue.
So, the problem is not in your code, but in the way that LibreOffice (Writer, Impress, and all the other apps) integrate with the browser libraries.
Hope that help you, it's not an usual issue.
Thanks
When you "copy" a document fragment, the program puts in the clipboard possibly more than a single version of what you copied.
Versions are tagged with their format.
Like for example if you paste the fragment in a text editor like vim it will choose a "text only" version because it doesn't deal with "text richness".
There might also be an HTML formatted version, and one in "rich text" format.
It's up to the pasting application to choose the right version.
If it doesn't specify any then the system (my experience was on Windows) chooses the most universally accepted one, that is, plain text.
It is explained in this MSDN page.