Skip to content

Commit

Permalink
Added #1
Browse files Browse the repository at this point in the history
  • Loading branch information
phrogg committed Jun 17, 2020
1 parent 014c730 commit 2de0f22
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 8 deletions.
32 changes: 26 additions & 6 deletions injectme.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
// default vals
var defaultText = "Sehr geehrter Herr/Frau %verk%,\n\nIch interessiere mich für %ware%. Und wollte fragen \n\nLiebe Grüße,\n%kauf%";

// parse the elements to extract the necessary things
var verk = document.getElementsByClassName("text-bold text-bigger text-force-linebreak")[0].firstElementChild.innerHTML.replace("\n ","");
var ware = document.getElementById("viewad-title").innerHTML.replace("\n ","");
var ware = document.getElementById("viewad-title").innerHTML.replace("\n ","");
var kauf = document.getElementsByClassName("formcontrol viewad-contact-contactName")[0].value;
var mess = document.getElementsByClassName("viewad-contact-message");

verk = verk[0].toUpperCase() + verk.substring(1,verk.length);

var nwstyle = "margin-top: 0px; margin-bottom: 0px; height: 200px;";

var nwmesag = "Sehr geehrter Herr/Frau "+verk+",\n\nIch interessiere mich für "+ware+". Und wollte fragen \n\nLiebe Grüße,\n"+kauf;
// load saved text
var nwmesag = "";

function afterLoadingText() {
// replace vars
nwmesag = nwmesag.replace("%verk%",verk).replace("%kauf%",kauf).replace("%ware%",ware);

mess[0].style = nwstyle;
mess[1].style = nwstyle;
// prepare msg fields
mess[0].style = nwstyle;
mess[1].style = nwstyle;
mess[0].value = nwmesag;
mess[1].value = nwmesag;
}

mess[0].value = nwmesag;
mess[1].value = nwmesag;
// load saved text
chrome.storage.sync.get(null, function (items) {
if(items.text != undefined){
nwmesag = items.text;
} else {
nwmesag = defaultText;
}
afterLoadingText();
});
12 changes: 10 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"manifest_version": 2,
"name": "eBayKleinanzeigenHelper",
"description": "Helping on Kleinanzeigen.",
"version": "0.2",
"author": "Phil Roggenbuck <ceo@roggstar.eu>",
"version": "0.3",
"author": "Phil Roggenbuck <me@phrogg.de>",

"icons": {
"36": "icons/Icon-36.png",
Expand All @@ -20,5 +20,13 @@
"matches": ["*://*.ebay-kleinanzeigen.de/s-anzeige/*"],
"js": ["injectme.js"]
}
],

"options_ui": {
"page": "options.html",
"chrome_style": true
},
"permissions": [
"storage"
]
}
92 changes: 92 additions & 0 deletions options.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
body {
background: #f9f9f9;
font-size: 15px;
border: 2px solid green;
border-radius: 4px;
font-family:Verdana, Geneva, sans-serif;
overflow: hidden;
margin: 15px;
}

h1 {
width: 100%;
margin: 0 0 10px 0;
background-color:green;
}

span {
display:inline;
}

.saved {
width: 20%;
border: 2px solid green;
border-radius: 4px;
margin: 12px 10px 12px 2%;
}

.unsaved {
width: 20%;
border: 2px solid red;
border-radius: 4px;
margin: 12px 10px 12px 2%;
}

.container {
display: block;
position: relative;
padding-left: 35px;
margin: 0 0 12px 2%;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

.container input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}

.checkmark {
position: absolute;
top: 0;
left: 0;
height: 20px;
width: 20px;
background-color: #eee;
}

.container:hover input ~ .checkmark {
background-color: #ccc;
}

.container input:checked ~ .checkmark {
background-color: green;
}

.checkmark:after {
content: "";
position: absolute;
display: none;
}

.container input:checked ~ .checkmark:after {
display: block;
}

.container .checkmark:after {
left: 6px;
top: 2px;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
17 changes: 17 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>KAFI Options</title>
<link rel="stylesheet" href="options.css">
<meta charset="UTF-8">
</head>
<body>
<h1> Options</h1>
</h1>
<label class="container">Automatic text 2 add in msg field newline(\n), use %verk% for the seller name, %kauf% for the buyer name (you) and %vware% for the product name.<br>When left blank it fills with the default text.
<br>
<span><textarea type="text" class="saved" id="text" rows="10" style="width:80%;"></textarea></span>
</label>
<script src="options.js"></script>
</body>
</html>
30 changes: 30 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// default vals
var defaultText = "Sehr geehrter Herr/Frau %verk%,\n\nIch interessiere mich für %ware%. Und wollte fragen \n\nLiebe Grüße,\n%kauf%";

//save the options
function save_options() {
let text = document.querySelector('#text').value;
if(text == ""){text = defaultText;} // reset text if empty
chrome.storage.sync.set({
text: text
}, function () {
var text = document.getElementById("text");
text.className = "unsaved";
setTimeout(function () {
text.className = "saved"; // maybe rebuild this function
}, 250);
});
}

function restore_options() {
chrome.storage.sync.get({text: defaultText}, function (items) {
document.querySelector('#text').value = items.text;
});
}

//load the options
document.addEventListener('DOMContentLoaded', restore_options);

document.querySelector("#text").addEventListener("change", function () {
save_options();
}, false);

0 comments on commit 2de0f22

Please sign in to comment.