Skip to content

Commit 953d165

Browse files
committedJan 9, 2018
add simple test index
1 parent 9b91bb2 commit 953d165

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

‎content.js

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
1-
var data = [
2-
{
3-
name: 'Test',
4-
texts: ['der getestet wird', 'der weiterhin getestet wird']
5-
}
6-
];
7-
81
extendText();
92

103
function getNameRegex(name) {
11-
return new RegExp('\b' + name + '\b');
4+
return new RegExp(name, 'g');
125
}
136

14-
function getNewString(date, isEndOfSentence) {
15-
return date.name + ', ' + date.texts[Math.floor(date.texts.length * Math.random())] + (isEndOfSentence ? '' : ',');
7+
function getNewString(item, isEndOfSentence) {
8+
return item.name + ', ' + item.texts[Math.floor(item.texts.length * Math.random())] + (isEndOfSentence ? '' : ',');
169
}
1710

1811
// extend text content with extension sentences
1912
function extendText() {
2013
findTextNodes(document.body).forEach(function(node) {
21-
data.forEach(function(date) {
22-
var parts = node.textContent.split(getNameRegex(date.name));
14+
data.forEach(function(item) {
15+
var parts = node.textContent.split(getNameRegex(item.name));
2316
for (var i = parts.length - 1; i > 0; i--) {
2417
var isEndOfSentence = /\s*[^a-z 0-9]/i.test(parts[i]);
25-
parts.splice(i, 0, getNewString(date, isEndOfSentence));
18+
parts.splice(i, 0, getNewString(item, isEndOfSentence));
2619
}
2720
node.textContent = parts.join('');
2821
});

‎data.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var data = [
2+
{
3+
name: 'Test',
4+
texts: [
5+
'der getestet wird',
6+
'der immer noch getestet wird'
7+
],
8+
src: [
9+
'https://de.wikipedia.org/wiki/Bj%C3%B6rn_H%C3%B6cke#Vermutete_Autorschaft_in_Zeitschriften_des_NPD-Umfelds'
10+
]
11+
}
12+
];

‎manifest.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"manifest_version": 2,
3-
4-
"name": "poli name ext",
3+
"name": "name context extension",
54
"description": "description.",
65
"version": "1.0",
76
"permissions": [
@@ -10,7 +9,7 @@
109
"content_scripts": [
1110
{
1211
"matches": ["<all_urls>"],
13-
"js": ["content.js"]
12+
"js": ["data.js", "content.js"]
1413
}
1514
]
1615
}

‎test/index.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<p>Test ipsum, dolor sit amet consectetur adipisicing elit. Consequatur quam, laboriosam beatae suscipit, dicta veniam voluptatum, saepe blanditiis distinctio quibusdam iure?</p>
11+
<p>Lorem ipsum dolor sit amet Test, consectetur adipisicing elit.</p>
12+
<p>Lorem ipsum dolor sit amet Test! consectetur adipisicing elit Test?</p>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)