Skip to content

Commit

Permalink
Add options window
Browse files Browse the repository at this point in the history
Currently it has only one option — to increase panel width.
  • Loading branch information
sv3k committed Dec 26, 2016
1 parent 0341aed commit 7d329ad
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 8 deletions.
18 changes: 18 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,23 @@
},
"browserAction": {
"message": "Scroll to the top or return"
},
"savedMsg": {
"message": "Saved"
},
"panelSizeTitle": {
"message": "Choose the panel size:"
},
"panelSize1": {
"message": "Tiny"
},
"panelSize1Desc": {
"message": "1 pixel width"
},
"panelSize2": {
"message": "Small"
},
"panelSize2Desc": {
"message": "10 pixels width"
}
}
18 changes: 18 additions & 0 deletions _locales/ru/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,23 @@
},
"browserAction": {
"message": "Прокрутить вверх или вернуться"
},
"savedMsg": {
"message": "Сохранено"
},
"panelSizeTitle": {
"message": "Выберите размер панели:"
},
"panelSize1": {
"message": "Крохотная"
},
"panelSize1Desc": {
"message": "ширина 1 пиксель"
},
"panelSize2": {
"message": "Маленькая"
},
"panelSize2Desc": {
"message": "ширина 10 пикселей"
}
}
9 changes: 8 additions & 1 deletion basic.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
bottom: 0 !important;
margin: 0 !important;
padding: 0 !important;
width: 1px !important;
height: 100% !important;
border-style: none !important;
box-shadow: none !important;
opacity: 0 !important;
z-index: 9999999999 !important;
}

.topscroll-chrome-extension-bar-1 {
width: 1px !important;
}

.topscroll-chrome-extension-bar-2 {
width: 10px !important;
}
22 changes: 16 additions & 6 deletions contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ topScroll = {

inject: () => {
topScroll.remove(); // Cleanup
var body = document.getElementsByTagName('body')[0];
var div = document.createElement('div');
div.id = topScroll.injectedName;
div.onclick = topScroll.scrollUp;
div.oncontextmenu = topScroll.scrollDown;
body.appendChild(div);
chrome.storage.sync.get({ panelType: 1 }, options => {
var body = document.getElementsByTagName('body')[0];
var div = document.createElement('div');
div.id = topScroll.injectedName;
div.className = topScroll.injectedName + '-' + options.panelType;
div.onclick = topScroll.scrollUp;
div.oncontextmenu = topScroll.scrollDown;
body.appendChild(div);

chrome.storage.onChanged.addListener(changes => {
var change = changes['panelType'];
if (change.oldValue != change.newValue) {
div.className = topScroll.injectedName + '-' + change.newValue;
}
});
});
},

remove: () => {
Expand Down
Binary file added lama.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"offline_enabled": true,
"author": "Anton Gorbunov",
"homepage_url": "https://github.com/sv3k/topscroll",
"permissions": ["<all_urls>"],
"permissions": ["<all_urls>", "storage"],
"content_scripts": [
{
"matches": ["<all_urls>"],
Expand All @@ -23,5 +23,9 @@
},
"browser_action": {
"default_title": "__MSG_browserAction__"
},
"options_ui": {
"page": "options.html",
"chrome_style": true
}
}
87 changes: 87 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>TopScroll Options</title>
<style>
body {
padding: 10px;
}
p {
color: gray;
margin-bottom: 0;
}
.saved {
float: right;
color: white;
background: forestgreen;
border: 5px solid forestgreen;
border-radius: 5px;
opacity: 0;
transition: .1s;
text-transform: uppercase;
}
.range-wrapper {
width: 200px;
margin: 15px auto 10px auto;
}
.range-labels {
margin: 0 7px;
font-weight: 700;
}
.range-input {
width: 100%;
display: block;
margin: 0;
}
.range-label-1 {
float: left;
text-align: left;
}
.range-label-1 > span {
margin-left: -50%;
}
.range-label-2 {
float: right;
text-align: right;
}
.range-label-2 > span {
margin-right: -50%;
}
.demo {
padding: 10px;
transition: 1s;
}
.demo-1 {
border-left: 1px solid blue;
}
.demo-2 {
border-left: 10px solid blue;
}
.demo-image {
width: 400px;
box-shadow: 0 0 10px gray;
}
</style>
</head>

<body>
<div id="saved" class="saved"></div>
<div id="panel-size-title"></div>
<div class="range-wrapper">
<div class="range-labels">
<div class="range-label-1"><span id="panel-size-1"></span></div>
<div class="range-label-2"><span id="panel-size-2"></span></div>
</div>
<input id="panel-type" class="range-input" type="range" min=1 max=2 list="panel-options">
<datalist id="panel-options">
<option>1</option>
<option>2</option>
</datalist>
</div>
<div id="demo-text" class="demo"></div>
<img class="demo-image" src="lama.jpg">
<p>TopScroll on <a href="https://github.com/sv3k/topscroll">GitHub</a></p>
<script src="options.js"></script>
</body>
</html>
34 changes: 34 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function saveOptions() {
var type = document.getElementById('panel-type').value;
var status = document.getElementById('saved');
chrome.storage.sync.set({
panelType: type
}, () => {
// Update status to let user know options were saved
status.style.opacity = 1;
setTimeout(() => {
status.style.opacity = 0;
}, 1000);
});
}

function showOptions() {
chrome.storage.sync.get({ panelType: 1 }, options => {
document.getElementById('panel-type').value = options.panelType;
var demo = document.getElementById('demo-text');
demo.className = 'demo demo-' + options.panelType;
demo.textContent = '← ' + chrome.i18n.getMessage('panelSize' + options.panelType + 'Desc');
});
}

// Init locale-specific strings
document.getElementById('saved').textContent = "✓ " + chrome.i18n.getMessage('savedMsg');
document.getElementById('panel-size-title').textContent = chrome.i18n.getMessage('panelSizeTitle');
document.getElementById('panel-size-1').textContent = chrome.i18n.getMessage('panelSize1');
document.getElementById('panel-size-2').textContent = chrome.i18n.getMessage('panelSize2');

document.addEventListener('DOMContentLoaded', showOptions);
document.getElementById('panel-type').addEventListener('change', () => {
saveOptions();
showOptions();
});

0 comments on commit 7d329ad

Please sign in to comment.