Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display track timestamp #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# Source
# ------
BUILD := manifest.json images/* build/mixcloud-tracklist.js
SOURCE := manifest.json images/* templates/*.dust tracklist.js
BUILD := manifest.json options.* images/* build/mixcloud-tracklist.js
SOURCE := manifest.json options.* images/* templates/*.dust tracklist.js


# Executable path
Expand Down
7 changes: 7 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
"strict_min_version": "45.0"
}
},
"permissions": [
"storage"
],
"options_ui": {
"page": "options.html",
"chrome_style": true
},
"content_scripts": [
{
"matches": ["*://*.mixcloud.com/*"],
Expand Down
46 changes: 46 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<title>Mixcloud Tracklist - Options</title>
<style>
.disabled {
color: #999;
}
.input-container {
padding: 5px;
}
label small {
display: block;
margin-left: 18px;
padding-top: 5px;
}
</style>
</head>

<body>

<p></p>

<form>
<div class="input-container">
<label class="disabled">
<input type="checkbox" name="feature.core" checked disabled/>
<strong>Core tracklist functionality</strong>
<small>Replace the missing tracklist</small>
</label>
</div>
<div class="input-container">
<label>
<input type="checkbox" name="feature.timestamp" id="timestamp"/>
<strong>Track timestamps</strong>
<small>Display timings of each track, if available, in the tracklist</small>
</label>
</div>
<div class="input-container">
<button id="save">Save changes</button>
</div>
</form>

<script src="options.js"></script>
</body>
</html>
19 changes: 19 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function save_options() {
var timestamp = document.getElementById('timestamp').checked;
chrome.storage.sync.set({
timestamp: timestamp
}, function () {
window.close();
});
}

function restore_options() {
chrome.storage.sync.get({
timestamp: false
}, function (items) {
document.getElementById('timestamp').checked = items.timestamp;
});
}

document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click', save_options);
2 changes: 1 addition & 1 deletion templates/tracklist.dust
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ul class="show-tracklist" ng-init="tracklistShown=false;audioLength={audio_length};sectionStartTimes=[]">
{#sections}
<li ng-hide="juno.sections.length">
<em>{track_number}</em>
{?timestamp}<em style="width:40px;">{timestamp}</em>{:else}<em>{track_number}</em>{/timestamp}
{?chapter}<b title="{chapter}">{chapter}</b>{:else}<b title="{title}">{title}</b>{/chapter}
{?artist}<small> by <span>{artist}</span></small>{/artist}
</li>
Expand Down
19 changes: 18 additions & 1 deletion tracklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,30 @@ function fetchData(location, fn) {
"json": true
}, (error, response, data) => {
if (!error && response.statusCode === 200 && data.cloudcast.sections.length > 0) {
fn(insertTrackNumber(data));
chrome.storage.sync.get({
timestamp: false
}, (options) => {
fn(insertTimestamp(insertTrackNumber(data), options));
});
} else {
console.error(error);
}
});
}

function insertTimestamp(data, options) {
data.cloudcast.sections.forEach((section, i) => {
if (section.start_time !== null && options.timestamp === true) {
const minutes = Math.floor(section.start_time / 60);
const seconds = ("0" + section.start_time % 60).slice(-2);
section.timestamp = `${minutes}:${seconds}`;
} else {
section.timestamp = null;
}
});
return data;
}

function insertTrackNumber(data) {
data.cloudcast.sections.forEach((section, i) => {
section.track_number = i + 1;
Expand Down