Skip to content

Commit

Permalink
Merge pull request #47 from snowsunny/fix_codes
Browse files Browse the repository at this point in the history
update for another service
  • Loading branch information
snowsunny authored Oct 3, 2020
2 parents 29718ae + c82cb81 commit bca39f1
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 77 deletions.
2 changes: 1 addition & 1 deletion novels-reader-crx/background.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions novels-reader-crx/content.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions novels-reader-crx/html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ <h2 class="subtitle">web page reader for syosetu.com</h2>
</div>
<div class="column is-half">
<div class="title sub" style="margin-top: 0px">ユーザー辞書</div>
<textarea class="textarea dictionary" data-id="user"></textarea>
<textarea class="textarea dictionary" data-id="user" data-domain="novels-reader"></textarea>
<p style="margin:10px 0px 10px"><b>無視するルビ(正規表現)</b></p>
<div class="content">
<pre>強調表現等で使わるルビを無視する為の設定を、正規表現で記述出来ます。<br>例:「^・+$」を設定すると「・」のみのルビを無視します。</pre>
<input class="input dictionary" data-id="userIgnoreRubies">
<input class="input dictionary" data-id="userIgnoreRubies" data-domain="novels-reader">
</div>
</div>
</div>
Expand Down
13 changes: 3 additions & 10 deletions novels-reader-crx/options.js

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
"webpack-extension-reloader": "^1.1.4"
},
"dependencies": {
"clipboard": "^2.0.6",
"jquery": "^3.5.0",
"localforage": "^1.9.0",
"lodash": "^4.17.19",
"roudokuka": "^0.1.2"
},
"scripts": {
"build": "gulp ; webpack --mode production",
"dev": "gulp ; webpack --mode development -w"
"build": "gulp; webpack --mode production",
"dev": "gulp; webpack --mode development -w"
}
}
7 changes: 4 additions & 3 deletions src/js/DictionariesManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class DictionariesManager {
}

async saveDictionary(newDictionary, forceFlag) {
let storageDictionary = this.getDictionary(newDictionary.id)
let storageDictionary = this.getDictionary({id: newDictionary.id, domain: newDictionary.domain})
if(storageDictionary) {
if(!forceFlag && storageDictionary.raw && newDictionary.raw) {
let newRubies = this.getNewRubiesOnly(newDictionary, storageDictionary)
Expand All @@ -29,8 +29,9 @@ export default class DictionariesManager {
return storageDictionary
}

getDictionary(id) {
return _find(this.dictionaries, {id: id})
getDictionary(findOption) {
// standard findOption: {id: 'xxx', domain: 'xxx'}
return _find(this.dictionaries, findOption)
}

async getDictionaries() {
Expand Down
2 changes: 2 additions & 0 deletions src/js/OptionsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export default class OptionsManager {
let oldDictionaries = JSON.parse(localStorage.getItem('dictionaries'))
if(oldDictionaries) {
oldDictionaries = oldDictionaries.map((dictionary) => {
dictionary.id === 'user' || dictionary.id === 'userIgnoreRubies' ?
dictionary.domain = 'novels-reader' : dictionary.domain = 'ncode.syosetu.com'
delete dictionary.rubies
return dictionary
})
Expand Down
5 changes: 2 additions & 3 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import DictionariesManager from 'DictionariesManager'
import _find from 'lodash/find'

chrome.runtime.onConnect.addListener(async (port) => {
let om = await new OptionsManager()
let dm = await new DictionariesManager()

port.onMessage.addListener(async (request) => {
switch(request.method) {
case 'getOptions':
let om = await new OptionsManager()
port.postMessage(await om.getInitOptions())
break

case 'saveDictionary':
let dm = await new DictionariesManager()
port.postMessage({
user: _find(dm.dictionaries, {id: 'user'}),
ignoreRubies: _find(dm.dictionaries, {id: 'userIgnoreRubies'}),
Expand Down
16 changes: 9 additions & 7 deletions src/js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import DictionariesManager from 'DictionariesManager'
let options = null
let dictionaries = null
let linesInfo = []
let voices = []
let voices = null
let analyzer = null
let dm = null

const getLinesInfo = ($lineElements) => {
let linesInfo = []
let data = []
$lineElements.each((index, lineElement) => {
let $lineElement = $(lineElement)
linesInfo.push({
data.push({
text: analyzer.checkIncludeRuby($lineElement.html()) ? $lineElement.data().readText : $lineElement.text(),
element: $lineElement
})
})
return linesInfo
return data
}

const cleanLinesInfoAndRemovePlayButton = (linesInfo) => {
Expand Down Expand Up @@ -65,13 +65,15 @@ const initializeData = async () => {
})

dm = await new DictionariesManager()

analyzer = await new pageAnalyzer(window.location.hostname)
let findDictionaryOption = {id: analyzer.module.novelId, domain: analyzer.domain}

options = await postMessage({method: 'getOptions', key: 'options'})
dictionaries = await postMessage({
method: 'saveDictionary',
dictionary: {
domain: analyzer.domain,
id: analyzer.module.novelId,
...findDictionaryOption,
name: analyzer.module.novelName
}
})
Expand All @@ -88,7 +90,7 @@ const initializeData = async () => {
dictionaries = await postMessage({
method: 'saveDictionary',
dictionary: {
id: analyzer.module.novelId,
...findDictionaryOption,
raw: options.autoSaveDictionary == 'on' ? analyzer.getDictionaryTextOfCurrentNovelPage() : ''
}
})
Expand Down
17 changes: 8 additions & 9 deletions src/js/options.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import _each from 'lodash/each'
import Clipboard from 'clipboard'
import Roudokuka from 'roudokuka'
import OptionsManager from 'OptionsManager'
import DictionariesManager from 'DictionariesManager'

let om = null
let dm = null

const saveDictionary = async (element) => {
let target = $(element)
const saveDictionaryForOptionPage = async (element) => {
let $target = $(element)
await dm.saveDictionary({
id: target.data().id,
raw: target.val()
...$target.data(),
raw: $target.val()
}, true)
}

Expand Down Expand Up @@ -68,10 +67,10 @@ $(async () => {
$('.input[data-id=userIgnoreRubies').val(dictionary.raw)
} else {
let novelButton = $(`<div class='column is-flex is-3-desktop is-4-tablet'><div class='novel-name-wrap is-flex'><div class='novel-name'>${dictionary.name}${dictionary.id})</div></div></div>`)
novelButton.find('.novel-name-wrap').data('id', dictionary.id).on('click', (e) => {
let dictionary = dm.getDictionary($(e.currentTarget).data().id)
novelButton.find('.novel-name-wrap').data({id: dictionary.id, domain: dictionary.domain}).on('click', (e) => {
let dictionary = dm.getDictionary($(e.currentTarget).data())
$('#dictionary-modal-label').text(`${dictionary.name}${dictionary.id})`)
$('#dictionary-modal-textarea').attr('data-id', dictionary.id).val(dictionary.raw)
$('#dictionary-modal-textarea').data({id: dictionary.id, domain: dictionary.domain}).val(dictionary.raw)
$('#dictionary-modal').addClass('is-active')
})
novelsDictionary.append(novelButton)
Expand All @@ -83,7 +82,7 @@ $(async () => {
})

$('.textarea.dictionary, .input.dictionary').on('change keyup', (e) => {
saveDictionary(e.currentTarget)
saveDictionaryForOptionPage(e.currentTarget)
})

$('.options input, .options select').on('change keyup', async (e) => {
Expand Down
4 changes: 1 addition & 3 deletions src/js/pageAnalyzer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ export default class PageAnalyzer {
if(!_find(this.rubies, ruby) && !this.checkIgnoreRubiesTest(ruby, dictionaries)) {
this.rubies.push(ruby)
}
return this.checkIgnoreRubiesTest(ruby, dictionaries)
? ruby.rb
: ruby.rt
return this.checkIgnoreRubiesTest(ruby, dictionaries) ? ruby.rb : ruby.rt
} else {
return splitRubyTagText
}
Expand Down
4 changes: 2 additions & 2 deletions src/pug/options.pug
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ html
| ^\*+$::
.column.is-half
.title.sub(style='margin-top: 0px') ユーザー辞書
textarea.textarea.dictionary(data-id='user')
textarea.textarea.dictionary(data-id='user' data-domain='novels-reader')
p(style='margin:10px 0px 10px')
b 無視するルビ(正規表現)
.content
pre
| 強調表現等で使わるルビを無視する為の設定を、正規表現で記述出来ます。
br
| 例:「^・+$」を設定すると「・」のみのルビを無視します。
input.input.dictionary(data-id='userIgnoreRubies')
input.input.dictionary(data-id='userIgnoreRubies' data-domain='novels-reader')

.columns
.column
Expand Down
31 changes: 0 additions & 31 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1675,15 +1675,6 @@ [email protected]:
dependencies:
source-map "~0.6.0"

clipboard@^2.0.6:
version "2.0.6"
resolved "https://registry.yarnpkg.com/clipboard/-/clipboard-2.0.6.tgz#52921296eec0fdf77ead1749421b21c968647376"
integrity sha512-g5zbiixBRk/wyKakSwCKd7vQXDjFnAMGHoEyBogG/bw9kTD9GvdAvaoRR1ALcEzt3pVKxZR0pViekPMIS0QyGg==
dependencies:
good-listener "^1.2.2"
select "^1.1.2"
tiny-emitter "^2.0.0"

cliui@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-3.2.0.tgz#120601537a916d29940f934da3b48d585a39213d"
Expand Down Expand Up @@ -2052,11 +2043,6 @@ define-property@^2.0.2:
is-descriptor "^1.0.2"
isobject "^3.0.1"

delegate@^3.1.2:
version "3.2.0"
resolved "https://registry.yarnpkg.com/delegate/-/delegate-3.2.0.tgz#b66b71c3158522e8ab5744f720d8ca0c2af59166"
integrity sha512-IofjkYBZaZivn0V8nnsMJGBr4jVLxHDheKSW88PyxS5QC4Vo9ZbZVvhzlSxY87fVq3STR6r+4cGepyHkcWOQSw==

des.js@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/des.js/-/des.js-1.0.1.tgz#5382142e1bdc53f85d86d53e5f4aa7deb91e0843"
Expand Down Expand Up @@ -2749,13 +2735,6 @@ glogg@^1.0.0:
dependencies:
sparkles "^1.0.0"

good-listener@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/good-listener/-/good-listener-1.2.2.tgz#d53b30cdf9313dffb7dc9a0d477096aa6d145c50"
integrity sha1-1TswzfkxPf+33JoNR3CWqm0UXFA=
dependencies:
delegate "^3.1.2"

graceful-fs@^4.0.0, graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.4:
version "4.2.4"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
Expand Down Expand Up @@ -4681,11 +4660,6 @@ schema-utils@^2.6.5:
ajv "^6.12.4"
ajv-keywords "^3.5.2"

select@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/select/-/select-1.1.2.tgz#0e7350acdec80b1108528786ec1d4418d11b396d"
integrity sha1-DnNQrN7ICxEIUoeG7B1EGNEbOW0=

semver-greatest-satisfied-range@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/semver-greatest-satisfied-range/-/semver-greatest-satisfied-range-1.1.0.tgz#13e8c2658ab9691cb0cd71093240280d36f77a5b"
Expand Down Expand Up @@ -5067,11 +5041,6 @@ timers-browserify@^2.0.4:
dependencies:
setimmediate "^1.0.4"

tiny-emitter@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/tiny-emitter/-/tiny-emitter-2.1.0.tgz#1d1a56edfc51c43e863cbb5382a72330e3555423"
integrity sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==

[email protected]:
version "0.0.33"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
Expand Down

0 comments on commit bca39f1

Please sign in to comment.