Skip to content

Commit 41bfe2b

Browse files
author
jm-factorin
committed
Revise code render function
-- use ChatWork TimelineView -- Optimize performance
1 parent c944d21 commit 41bfe2b

5 files changed

Lines changed: 34 additions & 15 deletions

File tree

css/github.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/app.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1+
(function () {
2+
'use strict';
13

2-
//noinspection JSCheckFunctionSignatures
3-
$(document).ready(function() {
4-
setInterval(function() {
5-
$('code.chatCode').each(function(i, block) {
6-
if (!$(block).hasClass('hljs')) {
7-
hljs.highlightBlock(block);
8-
}
4+
var doRenderChatCode = function (timeline) {
5+
var $timeline = $('<div></div>').html(timeline);
6+
var $messages = $timeline.find('.chatTimeLineMessage');
7+
8+
if (!$messages.length) {
9+
return;
10+
}
11+
12+
$messages.find('code.chatCode').each(function (i, block) {
13+
hljs.highlightBlock(block);
914
});
10-
}, 100);
11-
});
15+
16+
return $timeline.html();
17+
};
18+
19+
var renderTimeLine = TimeLineView.prototype.renderTimeLine;
20+
TimeLineView.prototype.renderTimeLine = function (a, b) {
21+
b = doRenderChatCode(b);
22+
renderTimeLine.apply(TimeLineView, [a, b]);
23+
};
24+
})();

js/extension.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
var link = document.createElement('link');
22
link.rel = 'stylesheet';
3-
link.href = '//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/github.min.css';
3+
link.href = chrome.extension.getURL('css/github.min.css');
44
document.querySelector('head').appendChild(link);
55

66
var script = document.createElement('script');
77
script.type = 'text/javascript';
8-
script.src = '//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/highlight.min.js';
8+
script.src = chrome.extension.getURL('js/highlight.min.js');
99
document.querySelector('body').appendChild(script);
1010

1111
var app = document.createElement('script');

js/highlight.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifest.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "ChatWork Code Highlight!",
4-
"version": "1.0.1",
4+
"version": "2.0.0",
55
"description": "ChatWork Code Highlight!",
66
"icons": {
77
"128": "icons/128.png",
@@ -10,17 +10,20 @@
1010
},
1111
"permissions": [
1212
"https://kcw.kddi.ne.jp/*",
13+
"https://www.chatwork.com/*",
1314
"tabs"
1415
],
15-
"short_name": "ChatWork Code",
16+
"short_name": "CW Code Highlight",
1617
"content_scripts": [
1718
{
18-
"matches": ["https://kcw.kddi.ne.jp/*"],
19+
"matches": ["https://kcw.kddi.ne.jp/*", "https://www.chatwork.com/*"],
1920
"js": ["js/extension.js"],
2021
"run_at": "document_end"
2122
}
2223
],
2324
"web_accessible_resources": [
24-
"js/app.js"
25+
"js/app.js",
26+
"js/highlight.min.js",
27+
"css/github.min.css"
2528
]
2629
}

0 commit comments

Comments
 (0)