-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Download page plain text
- Loading branch information
Showing
7 changed files
with
118 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,114 @@ | ||
var body = document.body; | ||
var style = document.body.style; | ||
var titleLb = 'Title: '; | ||
if (!body.innerText.startsWith(titleLb)) { | ||
var title = titleLb + document.title; | ||
title += '\n' + Array(title.length + 1).join('-'); | ||
body.innerText = title + '\n\n' + body.innerText; | ||
} else { | ||
body.innerText = body.innerText; | ||
var extensionId = 'chrome-extension-plain-text'; | ||
if (document.querySelectorAll('#' + extensionId).length == 0) { | ||
|
||
//BODY | ||
var body = document.createElement('div'); | ||
|
||
//HEADER | ||
var header = document.createElement('div'); | ||
header.id = extensionId; | ||
header.style.setProperty('float', 'right', 'important'); | ||
|
||
// EDIT | ||
var editLink = document.createElement('a'); | ||
editLink.innerText = 'Edit'; | ||
editLink.href = '#'; | ||
editLink.style.setProperty('color', '#0366d6'); | ||
editLink.style.setProperty('text-decoration', 'unset'); | ||
editLink.style.setProperty('background', '#dddddd'); | ||
editLink.style.setProperty('border', '1px solid #aaaaaa'); | ||
editLink.style.setProperty('border-radius', '4px'); | ||
editLink.style.setProperty('padding', '3px 5px'); | ||
editLink.style.setProperty('font-weight', 'bold'); | ||
editLink.onclick = function () { | ||
if (body.contentEditable.toLowerCase() == 'true') { | ||
body.contentEditable = 'false'; | ||
editLink.style.setProperty('background', '#dddddd'); | ||
editLink.style.setProperty('color', '#0366d6'); | ||
editLink.style.setProperty('border', '1px solid #aaaaaa'); | ||
} else { | ||
body.contentEditable = 'true'; | ||
editLink.style.setProperty('border', '1px solid #0000ac'); | ||
editLink.style.setProperty('background', '#0366d6'); | ||
editLink.style.setProperty('color', '#ffffff'); | ||
} | ||
|
||
} | ||
header.appendChild(editLink); | ||
|
||
// DOWNLOAD | ||
var downloadLink = document.createElement('a'); | ||
downloadLink.innerText = 'Download'; | ||
downloadLink.href = '#'; | ||
downloadLink.style.setProperty('margin-left', '5px'); | ||
downloadLink.style.setProperty('color', '#0366d6'); | ||
downloadLink.style.setProperty('text-decoration', 'unset'); | ||
downloadLink.style.setProperty('background', '#dddddd'); | ||
downloadLink.style.setProperty('border', '1px solid #aaaaaa'); | ||
downloadLink.style.setProperty('border-radius', '4px'); | ||
downloadLink.style.setProperty('padding', '3px 5px'); | ||
downloadLink.style.setProperty('font-weight', 'bold'); | ||
downloadLink.onclick = function () { | ||
downloadText('page-content.txt', body.innerText); | ||
} | ||
header.appendChild(downloadLink); | ||
|
||
// TITLE & TEXT | ||
var innerText = document.body.innerText; | ||
|
||
var titleLb = 'Title: '; | ||
if (!body.innerText.startsWith(titleLb)) { | ||
var title = titleLb + document.title; | ||
title += '\n' + Array(title.length + 1).join('-'); | ||
body.innerText = title + '\n\n' + innerText; | ||
} else { | ||
body.innerText = innerText; | ||
} | ||
|
||
// NEW BODY | ||
document.body.innerText = ''; | ||
document.head.innerText = ''; | ||
document.body.appendChild(header) | ||
document.body.appendChild(body) | ||
|
||
// STYLE | ||
var css = ':focus{ background-color: unset; outline: unset;}'; | ||
var globalStyle = document.createElement('style'); | ||
globalStyle.appendChild(document.createTextNode(css)); | ||
document.body.appendChild(globalStyle); | ||
|
||
var style = document.body.style; | ||
style.setProperty('padding', '10px', 'important'); | ||
style.setProperty('margin', '0', 'important'); | ||
style.setProperty('background', 'white', 'important'); | ||
style.setProperty('color', 'black', 'important'); | ||
style.setProperty('font-family', 'Courier New', 'important'); | ||
style.setProperty('font-size', '13px', 'important'); | ||
style.setProperty('text-align', 'left', 'important'); | ||
style.setProperty('line-height', '1.5', 'important'); | ||
|
||
// GO TO TOP | ||
document.body.scrollIntoView(); | ||
} | ||
|
||
style.setProperty('padding', '10px', 'important'); | ||
style.setProperty('margin', '0', 'important'); | ||
style.setProperty('background', 'white', 'important'); | ||
style.setProperty('color', 'black', 'important'); | ||
style.setProperty('font-family', 'Courier New', 'important'); | ||
style.setProperty('font-size', '13px', 'important'); | ||
style.setProperty('text-align', 'left', 'important'); | ||
// API | ||
// DOWNLOAD TEXT | ||
function downloadText(filename, text) { | ||
if (isWindows()) { | ||
text = text.replace(/\r?\n/g, "\r\n") | ||
} | ||
var element = document.createElement('a'); | ||
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); | ||
element.setAttribute('download', filename); | ||
element.style.display = 'none'; | ||
document.body.appendChild(element); | ||
element.click(); | ||
document.body.removeChild(element); | ||
} | ||
//OS | ||
function isWindows() { | ||
if (window && window.navigator && window.navigator.userAgent) { | ||
return window.navigator.userAgent.toLowerCase().indexOf("windows") != -1; | ||
} | ||
return false; | ||
} |