diff --git a/novels-reader-crx/content.js b/novels-reader-crx/content.js
index 14be4c1..9a23e80 100644
--- a/novels-reader-crx/content.js
+++ b/novels-reader-crx/content.js
@@ -15644,13 +15644,12 @@ 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 = $('
' + text + '
');
- if (checkIncludeRuby(text)) {
- lineElement.addClass('include-ruby');
+var setRubyData = function setRubyData($lineElement) {
+ if (checkIncludeRuby($lineElement.html())) {
+ $lineElement.addClass('include-ruby');
var divider = '__|novels|reader|ruby|tag|divider|__';
- var splitRubyTagTexts = text.replace(//gi, divider + '').replace(/<\/rp><\/ruby>/gi, '' + divider).split(divider);
+ var splitRubyTagTexts = $lineElement.html().replace(//gi, divider + '').replace(/<\/rp><\/ruby>/gi, '' + divider).split(divider);
var readText = splitRubyTagTexts.map(function (splitRubyTagText) {
if (checkIncludeRuby(splitRubyTagText)) {
var ruby = { rb: $(splitRubyTagText).find('rb').text(), rt: $(splitRubyTagText).find('rt').text() };
@@ -15662,32 +15661,28 @@ var getLineElement = function getLineElement(text, blankLineCount, element) {
return splitRubyTagText;
}
}).join('');
- lineElement.data({ readText: readText });
+ $lineElement.data({ readText: readText });
}
- return lineElement;
};
-var getLineElements = function getLineElements(element) {
- var splitTexts = element.html().split('
\n');
-
- var blankLineCount = 0;
- return splitTexts.map(function (text) {
- if (/\S/gi.test(text) == false) {
- blankLineCount++;
- } else {
- var lineElement = getLineElement(text, blankLineCount, element);
- blankLineCount = 0;
- return lineElement.prepend('
');
- }
- }).filter(function (lineElement) {
- return lineElement != undefined;
+var setPlayButtonElementsAndSetRubyData = function setPlayButtonElementsAndSetRubyData(lineElements) {
+ lineElements.each(function (index, lineElement) {
+ var $lineElement = $(lineElement);
+ setRubyData($lineElement);
+ $lineElement.prepend($('
'));
});
};
-var getLinesInfo = function getLinesInfo(lineElements) {
- return lineElements.map(function (lineElement) {
- return { text: checkIncludeRuby(lineElement.html()) ? lineElement.data().readText : lineElement.text(), element: lineElement };
+var getLinesInfo = function getLinesInfo($lineElements) {
+ var linesInfo = [];
+ $lineElements.each(function (index, lineElement) {
+ var $lineElement = $(lineElement);
+ linesInfo.push({
+ text: checkIncludeRuby($lineElement.html()) ? $lineElement.data().readText : $lineElement.text(),
+ element: $lineElement
+ });
});
+ return linesInfo;
};
var lineHighlight = function lineHighlight(lineElement) {
@@ -15714,32 +15709,24 @@ if ($('#novel_honbun').length) {
$('head').append('');
$('head').append('');
- var title = $('.novel_subtitle');
- var foreword = $('#novel_p');
- var body = $('#novel_honbun');
- var afterword = $('#novel_a');
-
var lineElements = {};
var linesInfo = [];
- if (options.title == 'on' && title.length) {
- lineElements.title = [title.prepend('
')];
- linesInfo = linesInfo.concat(getLinesInfo(lineElements.title));
- }
- if (options.foreword == 'on' && foreword.length) {
- lineElements.foreword = getLineElements(foreword);
- linesInfo = linesInfo.concat(getLinesInfo(lineElements.foreword));
- foreword.html(lineElements.foreword);
- }
- if (options.body == 'on' && body.length) {
- lineElements.body = getLineElements(body);
- linesInfo = linesInfo.concat(getLinesInfo(lineElements.body));
- body.html(lineElements.body);
- }
- if (options.afterword == 'on' && afterword.length) {
- lineElements.afterword = getLineElements(afterword);
- linesInfo = linesInfo.concat(getLinesInfo(lineElements.afterword));
- afterword.html(lineElements.afterword);
+ var targetElements = {
+ title: $('.novel_subtitle'),
+ foreword: $('#novel_p p'),
+ body: $('#novel_honbun p'),
+ afterword: $('#novel_a p')
+ };
+ for (var key in targetElements) {
+ if (options[key] == 'on' && targetElements[key].length) {
+ var filteredElements = targetElements[key].filter(function (index, element) {
+ return (/\S/gi.test($(element).text())
+ );
+ });
+ setPlayButtonElementsAndSetRubyData(filteredElements);
+ linesInfo = linesInfo.concat(getLinesInfo(filteredElements));
+ }
}
chrome.runtime.sendMessage({ method: 'saveDictionary', dictionary: {
diff --git a/novels-reader-crx/manifest.json b/novels-reader-crx/manifest.json
index 4033716..88356ad 100644
--- a/novels-reader-crx/manifest.json
+++ b/novels-reader-crx/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "novels-reader",
- "version": "1.0.1",
+ "version": "1.1.0",
"description": "Webpage reader for http://syosetu.com",
"content_scripts": [
{
diff --git a/src/js/content.js b/src/js/content.js
index fb4473c..6057768 100644
--- a/src/js/content.js
+++ b/src/js/content.js
@@ -24,13 +24,12 @@ const checkIgnoreRubiesTest = (ruby) => {
return dictionaries.ignoreRubies && dictionaries.ignoreRubies.raw && RegExp(dictionaries.ignoreRubies.raw, 'gi').test(ruby.rt)
}
-const getLineElement = (text, blankLineCount, element) => {
- let lineElement = $(`${text}
`)
- if(checkIncludeRuby(text)) {
- lineElement.addClass('include-ruby')
+const setRubyData = ($lineElement) => {
+ if(checkIncludeRuby($lineElement.html())) {
+ $lineElement.addClass('include-ruby')
const divider = '__|novels|reader|ruby|tag|divider|__'
- const splitRubyTagTexts = text.replace(//gi, `${divider}`).replace(/<\/rp><\/ruby>/gi, `${divider}`).split(divider)
+ const splitRubyTagTexts = $lineElement.html().replace(//gi, `${divider}`).replace(/<\/rp><\/ruby>/gi, `${divider}`).split(divider)
const readText = splitRubyTagTexts.map((splitRubyTagText) => {
if(checkIncludeRuby(splitRubyTagText)) {
const ruby = {rb: $(splitRubyTagText).find('rb').text(), rt: $(splitRubyTagText).find('rt').text()}
@@ -44,32 +43,28 @@ const getLineElement = (text, blankLineCount, element) => {
return splitRubyTagText
}
}).join('')
- lineElement.data({readText: readText})
+ $lineElement.data({readText: readText})
}
- return lineElement
}
-const getLineElements = (element) => {
- let splitTexts = element.html().split('
\n')
-
- let blankLineCount = 0
- return splitTexts.map((text) => {
- if(/\S/gi.test(text) == false) {
- blankLineCount++
- } else {
- let lineElement = getLineElement(text, blankLineCount, element)
- blankLineCount = 0
- return lineElement.prepend(`
`)
- }
- }).filter((lineElement) => {
- return lineElement != undefined
+const setPlayButtonElementsAndSetRubyData = (lineElements) => {
+ lineElements.each((index, lineElement) => {
+ let $lineElement = $(lineElement)
+ setRubyData($lineElement)
+ $lineElement.prepend($(`
`))
})
}
-const getLinesInfo = (lineElements) => {
- return lineElements.map((lineElement) => {
- return {text: checkIncludeRuby(lineElement.html()) ? lineElement.data().readText : lineElement.text(), element: lineElement}
+const getLinesInfo = ($lineElements) => {
+ let linesInfo = []
+ $lineElements.each((index, lineElement) => {
+ let $lineElement = $(lineElement)
+ linesInfo.push({
+ text: checkIncludeRuby($lineElement.html()) ? $lineElement.data().readText : $lineElement.text(),
+ element: $lineElement
+ })
})
+ return linesInfo
}
const lineHighlight = (lineElement) => {
@@ -130,32 +125,23 @@ $('head').append(``)
-const title = $('.novel_subtitle')
-const foreword = $('#novel_p')
-const body = $('#novel_honbun')
-const afterword = $('#novel_a')
-
let lineElements = {}
let linesInfo = []
-if(options.title == 'on' && title.length) {
- lineElements.title = [title.prepend(`
`)]
- linesInfo = linesInfo.concat(getLinesInfo(lineElements.title))
+const targetElements = {
+ title: $('.novel_subtitle'),
+ foreword: $('#novel_p p'),
+ body: $('#novel_honbun p'),
+ afterword: $('#novel_a p')
}
-if(options.foreword == 'on' && foreword.length) {
- lineElements.foreword = getLineElements(foreword)
- linesInfo = linesInfo.concat(getLinesInfo(lineElements.foreword))
- foreword.html(lineElements.foreword)
-}
-if(options.body == 'on' && body.length) {
- lineElements.body = getLineElements(body)
- linesInfo = linesInfo.concat(getLinesInfo(lineElements.body))
- body.html(lineElements.body)
-}
-if(options.afterword == 'on' && afterword.length) {
- lineElements.afterword = getLineElements(afterword)
- linesInfo = linesInfo.concat(getLinesInfo(lineElements.afterword))
- afterword.html(lineElements.afterword)
+for(let key in targetElements) {
+ if(options[key] == 'on' && targetElements[key].length) {
+ let filteredElements = targetElements[key].filter((index, element) => {
+ return /\S/gi.test($(element).text())
+ })
+ setPlayButtonElementsAndSetRubyData(filteredElements)
+ linesInfo = linesInfo.concat(getLinesInfo(filteredElements))
+ }
}
chrome.runtime.sendMessage({method: 'saveDictionary', dictionary: {
diff --git a/src/manifest.cson b/src/manifest.cson
index b4bdcdd..83cc5e3 100644
--- a/src/manifest.cson
+++ b/src/manifest.cson
@@ -1,6 +1,6 @@
manifest_version: 2
name: 'novels-reader'
-version: '1.0.1'
+version: '1.1.0'
description: 'Webpage reader for http://syosetu.com'