21 July, 2013

Copy and save webpage selection. Remove JavaScript code.

How to copy and save a webpage selection with JavaScript tags and code removed by using a mouse gesture, a keyboard shortcut or a context menu item.



NOTE: It's not fully automatic, because the Opera source viewer doesn't have the command "Apply Changes". So when the script opens the source viewer, one has to manually click "Apply Changes" and close the source viewer. Then the original webpage will have been changed and ready to be saved. The script adds the webpage's URL at the end of selection. ********************************************************************
  • Update: A quicker and maybe more reliable version of the code (using window.prompt):
    Enable javascript & Delay, 10 & Go to page,"javascript:(function(){var sel=document.createElement('div');title=document.title;var d = new Date();sel.appendChild(window.getSelection().getRangeAt(0).cloneContents());sel.innerHTML=sel.innerHTML.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,'');window.prompt('','<html>\n' + '<head>\n<title>' + title + '</title></head>\n<body style=max-width:700px;margin:auto !important>\n'+ sel.innerHTML +'\n\n\n<br><br><br>' + location.href+'\n<br>' +'Saved on: ' + d.toLocaleString()+'\n; &nbsp&nbsp'+Date().substring(25)+ '\n</body></html>')})()" & Delay, 100 & Copy & Click default button & Delay, 100 & View document source & Delay, 30 & Select all & Paste & Delay, 10 & Go to start
********************************************************************




  • Mouse gesture
    GestureRight, GestureUp, GestureDown=Enable javascript & Delay, 10 & Go to page,"javascript:(function(){var sel=document.createElement('div');title=document.title;sel.appendChild(window.getSelection().getRangeAt(0).cloneContents());document.open('application/xhtml+xml');sel.innerHTML=sel.innerHTML.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,'');document.write('<html>\n' + '<head>\n<title>' + title + '</title></head>\n<body style=max-width:1000px;margin:auto !important>\n'+ sel.innerHTML +'\n\n\n<br><br><br>' + location.href+ '\n</body></html>');document.close();})()" & delay,100 & Select all & Copy & Back & Delay, 60 & View document source & Delay, 30 & Select all & Paste & Delay, 10 & Go to start
  • Keyboard shortcut
    Ctrl G=Enable javascript & Delay, 10 & Go to page,"javascript:(function(){var sel=document.createElement('div');title=document.title;sel.appendChild(window.getSelection().getRangeAt(0).cloneContents());document.open('application/xhtml+xml');sel.innerHTML=sel.innerHTML.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,'');document.write('<html>\n' + '<head>\n<title>' + title + '</title></head>\n<body style=max-width:1000px;margin:auto !important>\n'+ sel.innerHTML +'\n\n\n<br><br><br>' + location.href+ '\n</body></html>');document.close();})()" & delay,100 & Select all & Copy & Back & Delay, 60 & View document source & Delay, 30 & Select all & Paste & Delay, 10 & Go to start
  • Change to menu.ini
    [Link Popup Menu]
    Item, Copy selection ="Enable javascript & Delay, 10 & Go to page,"javascript:(function(){var sel=document.createElement('div');title=document.title;sel.appendChild(window.getSelection().getRangeAt(0).cloneContents());document.open('application/xhtml+xml');sel.innerHTML=sel.innerHTML.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,'');document.write('<html>\n' + '<head>\n<title>' + title + '</title></head>\n<body style=max-width:1000px;margin:auto !important>\n'+ sel.innerHTML +'\n\n\n<br><br><br>' + location.href+ '\n</body></html>');document.close();})()" & delay,100 & Select all & Copy & Back & Delay, 60 & View document source & Delay, 30 & Select all & Paste & Delay, 10 & Go to start"
RegEx in .replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,'') is used to remove JavaScript code.

No comments:

Post a Comment