Skip to content
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.DS_Store
.idea/
5 changes: 5 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
importScripts(
'js/unmark/base.js',
'js/unmark/omnibox.js',
'js/unmark/contexts.js'
);
30 changes: 30 additions & 0 deletions css/content.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.unmark-message {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 2147483647;
width: 360px;
max-width: 90vw;
font-family: sans-serif;
text-align: left;
box-shadow: 7px 7px 30px #888;
border: 1px solid #ddd;
background: #fff;
}

.unmark-message__header {
background-color: #333;
color: #ccc;
font-size: 14px;
text-transform: uppercase;
padding: 10px;
}

.unmark-message__body {
background-color: #fff;
color: #666;
font-size: 18px;
border-bottom: 5px solid #ddd;
padding: 25px 10px;
}
80 changes: 80 additions & 0 deletions css/options.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#options {
display: block;
}
.options-card {
max-width: 520px;
margin: 24px auto 40px;
}

#message {
display: none;
width: 100%;
line-height: 20px;
}

#message-text {
display: inline-block;
line-height: 20px;
}

html,
body {
background: #ffffff;
}

body.unmark-solo {
overflow: auto;
padding: 24px 0;
}


.options-header span {
color: #989597;
font-size: 13px;
display: block;
}

.options-settings {
color: #a5a6aa;
}

.options-label {
display: block;
font-family: "Montserrat", sans-serif;
letter-spacing: 1px;
text-transform: uppercase;
font-size: 11px;
color: #a5a6aa;
margin-bottom: 10px;
}

.options-input {
width: 100%;
border: 1px solid #e6e5e6;
border-radius: 4px;
padding: 10px 12px;
font-size: 14px;
color: #3d3d3d;
}

.options-help {
margin: 10px 0 0;
font-size: 12px;
color: #989597;
}

.options-actions {
display: flex;
flex-direction: column;
gap: 12px;
}

.options-actions .danger {
width: 220px;
}

.options-status {
font-size: 12px;
color: #989597;
display: inline-block;
}
6 changes: 2 additions & 4 deletions js/third_party/jquery.js

Large diffs are not rendered by default.

192 changes: 161 additions & 31 deletions js/unmark/base.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
var unmark = (unmark === undefined) ? {} : unmark;
unmark.host = 'https://unmark.it';
unmark.default_host = 'https://unmark.it';
unmark.host = unmark.default_host;
unmark._hostLoaded = false;
unmark.storage = (typeof chrome !== 'undefined' && chrome.storage && chrome.storage.sync) ? chrome.storage.sync : null;
unmark.paths = {
'add' : '/mark/add',
'archive' : '/mark/archive',
Expand All @@ -13,45 +16,160 @@ unmark.paths = {
};
unmark.special_chars = {'\\+': '+'};

unmark.normalizeHost = function(value)
{
if (unmark.empty(value)) {
return unmark.default_host;
}

var host = value.trim();
if (host.indexOf('://') < 0) {
host = 'https://' + host;
}

try {
var url = new URL(host);
return url.origin;
}
catch (e) {
return unmark.default_host;
}
};

unmark.getHost = function(callback)
{
if (! unmark.isFunction(callback)) {
return;
}

if (! unmark.storage) {
callback(unmark.host);
return;
}

if (unmark._hostLoaded) {
callback(unmark.host);
return;
}

unmark.storage.get({'host': unmark.default_host}, function(res)
{
unmark.host = unmark.normalizeHost(res.host);
unmark._hostLoaded = true;
callback(unmark.host);
});
};

unmark.isFunction = function(v)
{
return (typeof v === 'function');
};

unmark.ajax = function(path, query, method, success_callback, error_callback)
{
method = method.toUpperCase();
method = (method != 'GET' && method != 'POST') ? 'POST' : method;
$.ajax({
url: unmark.host + path,
data: query,
dataType: 'json',
type: method,
headers: {'X-Requested-With': 'XMLHttpRequest', 'X-Chrome-Extension': '1'},
timeout: 2000,
success: function(obj)
{
//unmark.ext.log('success');
//unmark.ext.log(obj);
//unmark.ext.log($.isFunction(success_callback));
if ($.isFunction(success_callback)) {
success_callback(obj);
}
},
error: function(xhr, status, err)
{
var obj = {'xhr': xhr, 'status': status, 'error': err};
unmark.getHost(function(host)
{
if (typeof $ !== 'undefined' && $.ajax) {
$.ajax({
url: host + path,
data: query,
dataType: 'json',
type: method,
headers: {'X-Requested-With': 'XMLHttpRequest', 'X-Chrome-Extension': '1'},
timeout: 2000,
success: function(obj)
{
//unmark.ext.log('success');
//unmark.ext.log(obj);
//unmark.ext.log(unmark.isFunction(success_callback));
if (unmark.isFunction(success_callback)) {
success_callback(obj);
}
},
error: function(xhr, status, err)
{
var obj = {'xhr': xhr, 'status': status, 'error': err};

if (xhr.responseJSON && xhr.responseJSON.errors) {
for (var i in xhr.responseJSON.errors) {
obj.status = i;
obj.error = xhr.responseJSON.errors[i];
}
}

//unmark.ext.log('fail');
//unmark.ext.log(obj);
//unmark.ext.log(unmark.isFunction(error_callback));

if (xhr.responseJSON.errors) {
for (var i in xhr.responseJSON.errors) {
obj.status = i;
obj.error = xhr.responseJSON.errors[i];
if (unmark.isFunction(error_callback)) {
error_callback(obj);
}
}
}
});
return;
}

var url = host + path;
if (method === 'GET' && ! unmark.empty(query)) {
url += (url.indexOf('?') === -1 ? '?' : '&') + query;
}

var controller = new AbortController();
var timeout = setTimeout(function()
{
controller.abort();
}, 2000);

//unmark.ext.log('fail');
//unmark.ext.log(obj);
//unmark.ext.log($.isFunction(error_callback));
var options = {
method: method,
headers: {
'X-Requested-With': 'XMLHttpRequest',
'X-Chrome-Extension': '1'
},
signal: controller.signal
};

if ($.isFunction(error_callback)) {
if (method === 'POST') {
options.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
options.body = query || '';
}

fetch(url, options).then(function(res)
{
return res.json().catch(function()
{
return {};
}).then(function(data)
{
clearTimeout(timeout);
if (res.ok) {
if (unmark.isFunction(success_callback)) {
success_callback(data);
}
return;
}

var obj = {'xhr': null, 'status': res.status.toString(), 'error': res.statusText};
if (data && data.errors) {
for (var i in data.errors) {
obj.status = i;
obj.error = data.errors[i];
}
}
if (unmark.isFunction(error_callback)) {
error_callback(obj);
}
});
}).catch(function(err)
{
clearTimeout(timeout);
var obj = {'xhr': null, 'status': '0', 'error': (err && err.message) ? err.message : err};
if (unmark.isFunction(error_callback)) {
error_callback(obj);
}
}
});
});
};

Expand All @@ -61,6 +179,18 @@ unmark.empty = function(v)
return (v === false || v === '' || v === null || v === 0 || v === undefined || l < 1);
};

if (typeof chrome !== 'undefined' && chrome.storage && chrome.storage.onChanged) {
chrome.storage.onChanged.addListener(function(changes, area)
{
if (area !== 'sync' || ! changes.host) {
return;
}

unmark.host = unmark.normalizeHost(changes.host.newValue);
unmark._hostLoaded = true;
});
}

unmark.isset = function(v)
{
return (v !== undefined);
Expand All @@ -81,4 +211,4 @@ unmark.replaceSpecial = function(str)
unmark.urlEncode = function(str)
{
return encodeURIComponent(unmark.replaceSpecial(str));
};
};
Loading