L
L
lukoie2015-12-23 05:50:39
JavaScript
lukoie, 2015-12-23 05:50:39

How can it be that the text is copied differently from what is entered on the page?

Here is the link:
lifter.com.ua/CHetire-neogidannih-prichini-pochemu...
see the title? Now select it, hit control-c, and paste it somewhere.
I have it inserted here in this form:
"Four unexpected reasons, why are you asking usatshvim"
How is it done? And most importantly - why, in fact, this may be needed?
PS: oh, I'm stupid, I understood why - so as not to copy-paste the article. Cool idea. But the question remains - HOW?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2015-12-23
@alexey-m-ukolov

function copyProtect(event) {
  var rows = window.getSelection().toString().split(/\n/);
  for (var r = 0; r < rows.length; r++) {
    var words = rows[r].split(/\s/);
    for (var i = 0; i < words.length; i++) {
      if (words[i].length > 6) {
        words[i] = words[i].split("");
        for (var j = 2; j < words[i].length - 2; j += 2) {
          var tmp = words[i][j];
          words[i][j] = words[i][j + 1];
          words[i][j + 1] = tmp;
        }
        words[i] = words[i].join("");
      }
    }
    rows[r] = words.join(" ");
  }
  event.preventDefault();
  event.clipboardData.setData("text", rows.join("\n"));
  if (window.localStorage['fb_uid']) {
    XHR.request("http://counter.lifter.com.ua/desktop/oncopy.php", null, "id=" + window.localStorage['fb_uid'], "application/x-www-form-urlencoded", "POST");
  }
}

lifter.com.ua/tpls/lifter/template.js

M
mortefy, 2015-12-23
@mortefy

this is a script that copies to the clipboard the text that the script obviously modified.
it's like a "chip" corresponding to the topic.
this may be needed when leaving copyright text from the site (for example, I want to add a link to my site to the copied text)
Script by pressing two keys
Working with the clipboard
Ready-made solution

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question