Skip to content

Commit 41a918e

Browse files
authored
Version 0.0.1
Version 0.0.1
2 parents b8efb7e + 88ce359 commit 41a918e

22 files changed

Lines changed: 1213 additions & 54 deletions

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
**ENGLISH BELOW**
2+
3+
# 나중에 위키 읽기 #
4+
5+
위키 사이트를 이용하다보면 읽고 싶은 문서가 많아서 미리 여러 탭을 띄워두는 경우가 많습니다.
6+
7+
지나치게 많은 탭을 띄운 탓에 브라우저가 느려져서 일부 탭을 닫을 수 밖에 없는 경우도 있습니다. 또한 닫아버린 문서를 기억해내지 못해서 읽지 못하는 경우도 있습니다.
8+
9+
**나중에 위키 읽기** 확장을 이용하면 더 이상 탭을 많이 열 필요도, 보려고 했던 문서를 잊어먹을 염려도 없습니다.
10+
11+
## 기능 ##
12+
13+
![우클릭 메뉴](doc/res/rightclick.ko.png)
14+
15+
보고 싶은 문서에 마우스를 대고 우클릭을 하면 나오는 메뉴를 누르면 읽기 목록에 바로 추가됩니다.
16+
17+
![확장 사용 화면](doc/res/use.ko.png)
18+
19+
읽기 목록은 화면 아래에 표시되고, 문서 제목을 클릭하면 해당 문서로 이동하고, 옆의 × 버튼을 누르면 읽기 목록에서 삭제할 수 있습니다.
20+
21+
[화면의 문서 - 한국어 위키백과 수염고래 문서](https://ko.wikipedia.org/wiki/%EC%88%98%EC%97%BC%EA%B3%A0%EB%9E%98)
22+
23+
## 지원하는 위키 ##
24+
25+
* 위키백과 (모든 언어)
26+
* 나무위키
27+
28+
지원하는 위키는 계속 추가될 예정입니다.
29+
30+
## 개발과 기여 ##
31+
32+
소스코드는 **GPLv3**로 배포됩니다.
33+
34+
모든 형태의 기여를 환영합니다.
35+
36+
새로운 위키 사이트를 추가하고 싶다면 [새로운 위키 사이트 추가하기](doc/HowToAddNewSite.md)를 참고해주세요.
37+
38+
# Read Wiki Later
39+
40+
When you use a wiki site, there are many documents you want to read, so you often have several tabs in advance.
41+
42+
Sometimes your browser slows down due to too many tabs, forcing you to close some. In some cases, you may not be able to remember the closed document and read it.
43+
44+
With this extension, you don't have to open as many tabs anymore, and you don't have to worry about forgetting what you've been looking at.
45+
46+
## Features ##
47+
48+
![Use right-click menu to add](doc/res/rightclick.en.png)
49+
50+
Right-click the document you want to view, and then click the menu that appears to add it to the reading list immediately.
51+
52+
![Reading list bar below](doc/res/use.en.png)
53+
54+
The reading list is displayed at the bottom of the screen, and you can click the title of the document to go to it, and you can click the x button next to it to delete it from the reading list.
55+
56+
[Document of Screenshots - English Wikipedia Baleen Whale](https://en.wikipedia.org/wiki/Baleen_whale)
57+
58+
## Supported Wiki sites ##
59+
60+
* Wikipedia (All languages)
61+
* NamuWiki (Korean)
62+
63+
## Contribution ##
64+
65+
Source code is distributed in **GPLv3**.
66+
67+
We welcome all forms of contribution.
68+
69+
If you want to add new wiki sites, see [Add new wiki site]((doc/HowToAddNewSite.md)).

_locales/en_US/messages.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"appName": {
3-
"message": "Wiki Later"
3+
"message": "Read Wiki Later"
44
},
55
"appDesc": {
6-
"message": "Que wiki documents at read later"
6+
"message": "Que wiki documents into list for after read"
77
},
88
"menuAddReadLater": {
9-
"message": "Add to read later"
9+
"message": "Add to list"
1010
}
1111
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"appName": {
3-
"message": "Wiki 나중에 읽기"
3+
"message": "나중에 위키 읽기"
44
},
55
"appDesc": {
66
"message": "위키의 문서를 나중에 읽을 수 있도록 저장합니다."
7+
},
8+
"menuAddReadLater": {
9+
"message": "나중에 읽기 목록에 추가"
710
}
811
}

core/background.js

Lines changed: 84 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
1-
// Context Menu ID
2-
const menuAddReadLaterId = "contextMenuAddReadLater"
1+
/// Common Constants
2+
3+
// Site value
4+
const siteValues = [
5+
{
6+
"key": "namu",
7+
"regex": /namu\.wiki\/w\//,
8+
"url": "namu.wiki/w/"
9+
},
10+
{
11+
"key": "wikipedia",
12+
"regex": /[a-z][a-z]\.wikipedia\.org\/wiki\//,
13+
"url": "%l.wikipedia.org/wiki/",
14+
"exLang": /\.wikipedia\.org\/wiki\/.+/
15+
},
16+
]
317

418
// Page Keys
519
const keyPageUnknown = "unknown"
6-
const keyPageNamuWiki = "namu"
720

821
// Data Access Keys
922
const keyTypeList = "list"
1023
const keyTypePage = "page"
1124
const keyTypeDocument = "doc"
1225

26+
// Site value keys
27+
const keySiteKey = "key"
28+
const keySiteRegex = "regex"
29+
const keySiteUrl = "url"
30+
1331
// Actions
1432
const actionInsertCSS = "insertCSS"
33+
const actionOpenDocument = "openDoc"
1534

1635
// Regex for check url
1736
const reProtocol = /https{0,1}:\/\//
18-
const reNamuWiki = /namu\.wiki\/w\//
37+
const reLang = /\%l/
38+
39+
/// End of Common Constants
40+
41+
// Context Menu ID
42+
const menuAddReadLaterId = "contextMenuAddReadLater"
1943

2044
/// Init extension
2145

@@ -45,15 +69,25 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
4569
// Insert CSS
4670
case actionInsertCSS:
4771
// Insert common CSS
48-
console.log("Insert CSS: " + sender.tab.id.toString())
4972
chrome.scripting.insertCSS({
5073
files: [
51-
'core/overlay.css'
74+
'core/overlay.css',
75+
'core/styles/' + message.key + '.css'
5276
],
5377
target: {
5478
tabId: sender.tab.id
5579
}
5680
})
81+
// Send response
82+
sendResponse({
83+
"result": true
84+
})
85+
break
86+
// Open document
87+
case actionOpenDocument:
88+
const header = "https://"
89+
const url = header + message.pageUrl + message.uri
90+
chrome.tabs.update(sender.tab.id, {"url": url})
5791
sendResponse({
5892
"result": true
5993
})
@@ -63,33 +97,65 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
6397

6498
/// END Init
6599

100+
/**
101+
* Add document to read later list
102+
* @param {string} url Full path of document to add
103+
*/
66104
async function addReadLater(url) {
67105
// Parse url
68106
const result = parseUrl(url)
69-
// Get read later list
70-
const list = await getReadLaterList(result[keyTypePage])
71-
// Add document to read later list
72-
list.push(result[keyTypeDocument])
73-
// Save storage
74-
const data = {}
75-
data[result[keyTypePage]] = {}
76-
data[result[keyTypePage]][keyTypeList] = list
77-
chrome.storage.local.set(data)
107+
if (!isObjectEmpty(result)) {
108+
// Get read later list
109+
const list = await getReadLaterList(result[keyTypePage])
110+
// Add document to read later list
111+
list.push(result[keyTypeDocument])
112+
// Save storage
113+
const data = {}
114+
data[result[keyTypePage]] = {}
115+
data[result[keyTypePage]][keyTypeList] = list
116+
chrome.storage.local.set(data)
117+
}
78118
}
79119

120+
/**
121+
* Parse url to analyze document type and document name if url is valid. Otherwise, return empty
122+
* @param {string} url Full path of document
123+
* @returns {object} Include document type and name when url is valid
124+
*/
80125
function parseUrl(url) {
81126
// Remove protocol
82127
let link = url.replace(reProtocol, "")
83128
const data = {}
84129
// Check url
85-
if (reNamuWiki.test(link)) { // is NamuWiki
86-
data[keyTypeDocument] = link.replace(reNamuWiki, "")
87-
data[keyTypePage] = keyPageNamuWiki
130+
for(var i=0; i < siteValues.length; i++) {
131+
const regex = siteValues[i][keySiteRegex]
132+
if (regex.test(url)) { // URL is supported site
133+
data[keyTypeDocument] = link.replace(regex, "")
134+
data[keyTypePage] = siteValues[i][keySiteKey]
135+
break
136+
}
88137
}
89138
// Return value
90139
return data
91140
}
92141

142+
/// Utility method below
143+
144+
/**
145+
* Check object is empty or not
146+
* @param {object} obejct Any object
147+
* @returns {bool} Return true when object is empty
148+
*/
149+
function isObjectEmpty(obejct) {
150+
return Object.keys(obejct).length === 0 && obejct.constructor === Object
151+
}
152+
153+
/**
154+
* Get list of read later items for target page
155+
* @description If it does not exists, return empty list
156+
* @param {string} keyPage Key of page
157+
* @returns {Array} Return list of read later items for target page
158+
*/
93159
async function getReadLaterList(keyPage) {
94160
const result = await chrome.storage.local.get(keyPage)
95161
if (result != undefined && result[keyPage] != undefined && result[keyPage][keyTypeList] != undefined) {

0 commit comments

Comments
 (0)