Skip to content

Commit

Permalink
bugfix for ignore rubies
Browse files Browse the repository at this point in the history
- 無視するルビに値が無い場合、ルビの処理で問題があったので修正した。
  • Loading branch information
snowsunny committed Apr 19, 2018
1 parent 40e143e commit a99c3c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
12 changes: 8 additions & 4 deletions novels-reader-crx/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -15640,6 +15640,10 @@ var checkIncludeRuby = function checkIncludeRuby(text) {
);
};

var checkIgnoreRubiesTest = function checkIgnoreRubiesTest(ruby) {
return dictionaries.ignoreRubies && dictionaries.ignoreRubies.raw && RegExp(dictionaries.ignoreRubies.raw, 'gi').test(ruby.rt);
};

var getLineElement = function getLineElement(text, blankLineCount, element) {
var lineElement = $('<p style=\'margin-top: ' + blankLineCount * element.css('line-height').replace('px', '') + 'px\'>' + text + '</p>');
if (checkIncludeRuby(text)) {
Expand All @@ -15650,10 +15654,10 @@ var getLineElement = function getLineElement(text, blankLineCount, element) {
var readText = splitRubyTagTexts.map(function (splitRubyTagText) {
if (checkIncludeRuby(splitRubyTagText)) {
var ruby = { rb: $(splitRubyTagText).find('rb').text(), rt: $(splitRubyTagText).find('rt').text() };
if (!(0, _find3.default)(rubies, ruby) && dictionaries.ignoreRubies && !RegExp(dictionaries.ignoreRubies.raw, 'gi').test(ruby.rt)) {
if (!(0, _find3.default)(rubies, ruby) && !checkIgnoreRubiesTest(ruby)) {
rubies.push(ruby);
}
return dictionaries.ignoreRubies && RegExp(dictionaries.ignoreRubies.raw, 'gi').test(ruby.rt) ? ruby.rb : ruby.rt;
return checkIgnoreRubiesTest(ruby) ? ruby.rb : ruby.rt;
} else {
return splitRubyTagText;
}
Expand Down Expand Up @@ -15753,7 +15757,7 @@ if ($('#novel_honbun').length) {
if (userRubies) {
linesInfo.forEach(function (lineInfo) {
userRubies.forEach(function (ruby) {
if (dictionaries.ignoreRubies && !RegExp(dictionaries.ignoreRubies.raw, 'gi').test(ruby.rt)) {
if (!checkIgnoreRubiesTest(ruby)) {
lineInfo.text = lineInfo.text.trim().replace(RegExp(ruby.rb, 'gi'), ruby.rt);
}
});
Expand All @@ -15762,7 +15766,7 @@ if ($('#novel_honbun').length) {
if (novelRubies) {
linesInfo.forEach(function (lineInfo) {
novelRubies.forEach(function (ruby) {
if (dictionaries.ignoreRubies && !RegExp(dictionaries.ignoreRubies.raw, 'gi').test(ruby.rt)) {
if (!checkIgnoreRubiesTest(ruby)) {
lineInfo.text = lineInfo.text.trim().replace(RegExp(ruby.rb, 'gi'), ruby.rt);
}
});
Expand Down
14 changes: 8 additions & 6 deletions src/js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const checkIncludeRuby = (text) => {
return /<ruby><rb>/gi.test(text)
}

const checkIgnoreRubiesTest = (ruby) => {
return dictionaries.ignoreRubies && dictionaries.ignoreRubies.raw && RegExp(dictionaries.ignoreRubies.raw, 'gi').test(ruby.rt)
}

const getLineElement = (text, blankLineCount, element) => {
let lineElement = $(`<p style='margin-top: ${blankLineCount * element.css('line-height').replace('px', '')}px'>${text}</p>`)
if(checkIncludeRuby(text)) {
Expand All @@ -30,10 +34,10 @@ const getLineElement = (text, blankLineCount, element) => {
const readText = splitRubyTagTexts.map((splitRubyTagText) => {
if(checkIncludeRuby(splitRubyTagText)) {
const ruby = {rb: $(splitRubyTagText).find('rb').text(), rt: $(splitRubyTagText).find('rt').text()}
if(!_find(rubies, ruby) && dictionaries.ignoreRubies && !RegExp(dictionaries.ignoreRubies.raw, 'gi').test(ruby.rt)) {
if(!_find(rubies, ruby) && !checkIgnoreRubiesTest(ruby)) {
rubies.push(ruby)
}
return dictionaries.ignoreRubies && RegExp(dictionaries.ignoreRubies.raw, 'gi').test(ruby.rt)
return checkIgnoreRubiesTest(ruby)
? ruby.rb
: ruby.rt
} else {
Expand Down Expand Up @@ -76,7 +80,6 @@ const lineUnHighlight = () => {
$('.novel_subtitle, #novel_p p, #novel_honbun p, #novel_a p').removeClass('highlight')
}


if($('#novel_honbun').length) {
const novelId = $('.contents1 .margin_r20').attr('href').replace(/\//g, '')
chrome.runtime.sendMessage({method: 'getOptions', key: 'options'}, (responseOptions) => {
Expand Down Expand Up @@ -155,7 +158,6 @@ if(options.afterword == 'on' && afterword.length) {
afterword.html(lineElements.afterword)
}


chrome.runtime.sendMessage({method: 'saveDictionary', dictionary: {
id: novelId,
raw: options.autoSaveDictionary == 'on' ? getDictionaryText(rubies) : ''
Expand All @@ -167,7 +169,7 @@ let novelRubies = dictionaries.novel.rubies.length ? _orderBy(dictionaries.novel
if(userRubies) {
linesInfo.forEach((lineInfo) => {
userRubies.forEach((ruby) => {
if(dictionaries.ignoreRubies && !RegExp(dictionaries.ignoreRubies.raw, 'gi').test(ruby.rt)) {
if(!checkIgnoreRubiesTest(ruby)) {
lineInfo.text = lineInfo.text.trim().replace(RegExp(ruby.rb, 'gi'), ruby.rt)
}
})
Expand All @@ -176,7 +178,7 @@ if(userRubies) {
if(novelRubies) {
linesInfo.forEach((lineInfo) => {
novelRubies.forEach((ruby) => {
if(dictionaries.ignoreRubies && !RegExp(dictionaries.ignoreRubies.raw, 'gi').test(ruby.rt)) {
if(!checkIgnoreRubiesTest(ruby)) {
lineInfo.text = lineInfo.text.trim().replace(RegExp(ruby.rb, 'gi'), ruby.rt)
}
})
Expand Down

0 comments on commit a99c3c5

Please sign in to comment.