super TMP

This commit is contained in:
alexadam 2016-07-27 14:54:45 +03:00
parent b168580a47
commit 606ed53f2a
9 changed files with 146 additions and 18 deletions

View file

@ -7,6 +7,9 @@
<body>
<div id="chapters" class="">
<h1>GIGI</h1>
<button id="savepage" type="button" name="button">Save Page</button>
<button id="superbuton" type="button" name="button">Edit Buffer 2</button>
<button id="title" type="button" name="button">Get Title</button>
</div>
<script src="chapter-editor.js" charset="utf-8"></script>

View file

@ -1,12 +1,42 @@
var chapterHolder = document.getElementById('chapters');
var list = document.createElement('ul');
var win = null;
for (var i = 0; i < 10; i++) {
var listItem = document.createElement('li');
var label = document.createElement('span');
label.innerHTML = 'i = ' + i;
listItem.appendChild(label);
list.appendChild(listItem);
document.getElementById("superbuton").onclick = function() {
win = window.open(chrome.extension.getURL('chapter-editor/editor.html'), '_blank');
win.focus();
};
document.getElementById('savepage').onclick = function() {
// chrome.tabs.query({
// currentWindow: true,
// active: true
// }, function(tab) {
// chrome.tabs.sendMessage(
// tab[0].id, {
// type: 'page-to-buffer'
// }
// );
// });
};
document.getElementById('title').onclick = function() {
chrome.tabs.query({
currentWindow: true,
active: true
}, function(tab) {
chrome.tabs.sendMessage(
tab[0].id, {
type: 'get-title'
},
function(response) {
var title = localStorage.getItem('title');
if (title === null) {
title = [];
} else {
title = JSON.parse(title);
}
chapterHolder.appendChild(list);
title.push(response);
localStorage.setItem('title', JSON.stringify(title));
}
);
});
};

View file

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Chapter Editor</title>
</head>
<body>
<h1>Chapter Editor</h1>
<div>
<ol id="chapters">
</ol>
</div>
<div class="">
<button id="closeButton" type="button" name="button">Cancel</button>
<button id="saveButton" type="button" name="button">Save</button>
</div>
<script src="editor.js" charset="utf-8"></script>
</body>
</html>

40
chapter-editor/editor.js Normal file
View file

@ -0,0 +1,40 @@
// var chapterHolder = document.getElementById('chapters');
var list = document.getElementById('chapters');
var title = localStorage.getItem('title');
if (title === null) {
title = [];
} else {
title = JSON.parse(title);
}
for (var i = 0; i < title.length; i++) {
var listItem = document.createElement('li');
var label = document.createElement('span');
label.innerHTML = title[i].title;
listItem.appendChild(label);
list.appendChild(listItem);
}
document.getElementById('closeButton').onclick = function () {
chrome.tabs.query({
currentWindow: true,
active: true
// Select active tab of the current window
}, function(tab) {
chrome.tabs.sendMessage(
// Send a message to the content script
tab[0].id, { line: 'countparas' }
);
});
};
browser.runtime.onMessage.addListener(function(request) {
console.log('cccccc', request);
});
document.getElementById('saveButton').onclick = function () {
window.open(window.location, '_self').close();
};

11
chapter-editor/menu.html Normal file
View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Chapter Editor</title>
</head>
<body>
<h1>Chapter Editor</h1>
</body>
</html>

9
gigi.js Normal file
View file

@ -0,0 +1,9 @@
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.type === 'get-title') {
console.log("AAAAAAAA 2", document.title);
sendResponse({title: document.title});
return true;
}
});

View file

@ -13,14 +13,14 @@
"content_scripts": [{
"matches": ["<all_urls>"],
"css": ["fonts.css"],
"js": ["jquery.js", "filesaver.js", "jszip.js", "jszip-utils.js", "pure-parser.js", "test.js"]
"js": ["jquery.js", "filesaver.js", "jszip.js", "jszip-utils.js", "pure-parser.js", "gigi.js"]
}],
"background": {
"scripts": ["background.js"]
"scripts": ["background2.js"]
},
"page_action": {
"browser_action": {
"default_icon": "",
"default_title": "Beastify",
"default_popup": "chapter-editor/chapter-editor.html"
@ -28,7 +28,8 @@
"permissions": [
"contextMenus",
"activeTab"
"activeTab",
"storage"
]
}

5
open-dialog.js Normal file
View file

@ -0,0 +1,5 @@
chrome.runtime.onMessage.addListener(function(request) {
console.log('rrrrrrrrrr', request.type);
});

17
test.js
View file

@ -222,7 +222,7 @@ function bibi(inp) {
function getEbookPages() {
try {
var allPages = sessionStorage.getItem('ebook');
var allPages = localStorage.getItem('ebook');
if (!allPages) {
allPages = [];
} else {
@ -251,7 +251,7 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
title: bibi(document.title), //gatPageTitle(document.title),
content: getHtmlAsString(pageSrc)
});
sessionStorage.setItem('ebook', JSON.stringify(allPages));
localStorage.setItem('ebook', JSON.stringify(allPages));
buildEbook();
} else if (request.type === 'selection') {
pageSrc = getSelectedNodes();
@ -261,8 +261,17 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
content: getHtmlAsString(pageSrc)
});
console.log('PUSH', JSON.stringify(allPages));
sessionStorage.setItem('ebook', JSON.stringify(allPages));
localStorage.setItem('ebook', JSON.stringify(allPages));
buildEbook();
} else if (request.type === 'page-to-buffer') {
pageSrc = document.getElementsByTagName('body')[0];
allPages.push({
url: getPageUrl(document.title),
title: bibi(document.title), //gatPageTitle(document.title),
content: getHtmlAsString(pageSrc)
});
console.log('merge');
localStorage.setItem('ebook', JSON.stringify(allPages));
} else if (request.type === 'show-buffer') {
// window.open(chrome.extension.getURL('chapter-editor/chapter-editor.html'), 'Chapter Editor');
@ -517,7 +526,7 @@ function buildEbook() {
}, 60000);
///////////// clean
sessionStorage.removeItem('ebook');
localStorage.removeItem('ebook');
allImgSrc = {};
imageIndex = 0;