Skip to content

Commit

Permalink
Merge pull request #103 from shgysk8zer0/feature/101
Browse files Browse the repository at this point in the history
Add support for custom subscription URLs
  • Loading branch information
shgysk8zer0 authored Aug 23, 2018
2 parents 0a4308f + fdade28 commit 7cbe971
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 5 deletions.
3 changes: 3 additions & 0 deletions img/icons.csv
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ mark-github,img/octicons/lib/svg/mark-github.svg
issues,img/octicons/lib/svg/issue-opened.svg
template,img/adwaita-icons/places/folder-templates.svg
star,img/adwaita-icons/places/user-bookmarks.svg
link,img/octicons/lib/svg/link.svg
margins,img/margins.svg
padding,img/padding.svg
rss,img/adwaita-icons/mimetypes/application-rss+xml.svg
feedly,img/logos/feedly.svg
inoreader,img/logos/inoreader.svg
tiny-tiny-rss,img/logos/tiny-tiny-rss.svg
nextcloud,img/logos/nextcloud.svg
2 changes: 1 addition & 1 deletion img/logos
Submodule logos updated 2 files
+8 −0 nextcloud.svg
+7 −0 tiny-tiny-rss.svg
23 changes: 22 additions & 1 deletion js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const defaultOpts = {
feedMargin: 0,
feedPadding: 7,
bgColor: '#ffffff',
nextcloudUrl: '',
tinyTinyRssUrl: '',
};

const storage = browser.storage.sync;
Expand All @@ -22,8 +24,11 @@ const ICONS = {
disabled: 'icons/subscribe-disabled.svg',
};

function openFeed({feed, target = 'current', service = 'rss', index = undefined} = {}) {
async function openFeed({feed, target = 'current', service = 'rss', index = undefined} = {}) {
let url = null;
const opts = await storage.get(['nextcloudUrl','tinyTinyRssUrl']);
console.info(opts);

switch (service) {
case 'feedly':
const feedly = new URL('https://feedly.com/i/subscription/feed/');
Expand All @@ -34,10 +39,21 @@ function openFeed({feed, target = 'current', service = 'rss', index = undefined}
url = new URL('https://www.inoreader.com');
url.searchParams.set('add_feed', feed);
break;
case 'tinyTinyRss':
url = new URL('/tt-rss/public.php', opts.tinyTinyRssUrl);
url.searchParams.set('op', 'subscribe');
url.searchParams.set('feed_url', feed);
break;
case 'nextcloud':
url = new URL('/index.php/apps/news', opts.nextcloudUrl);
url.searchParams.set('subscribe_to', feed);
break;
default:
url = new URL(feed);
}

console.info(url);

switch (target) {
case 'window':
browser.windows.create({url: url.toString()});
Expand Down Expand Up @@ -242,6 +258,11 @@ async function updateHandler(update) {

case '1.1.3':
storage.set({service: defaultOpts.service});
case '1.3.0':
storage.set({
nextcloudUrl: '',
tinyTinyRssUrl: '',
});
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ window.addEventListener('DOMContentLoaded', async () => {
}
}

function proxyEvent(target) {
return (event) => {
if (! event.target.classList.contains('proxied-event')) {
event.target.classList.add('proxied-event');
target.dispatchEvent(new Event(event.type));
setTimeout(() => event.target.classList.remove('proxied-event'), 100);
}
};
}

async function inputToggle(field) {
if (field instanceof Event) {
field = field.target;
}
$(`[name="${field.dataset.enables}"]`, field.closest('form')).forEach(input => {
input.disabled = ! field.checked;
input.hidden = ! field.checked;
input.required = field.checked;
Array.from(input.labels).forEach(label => label.hidden = ! field.checked);
});
}

async function setValuesFromStorage({
storage = browser.storage.sync,
form = document.forms.options,
Expand All @@ -43,6 +65,9 @@ window.addEventListener('DOMContentLoaded', async () => {
if (input.value === value) {
input.checked = true;
}
if (input.dataset.hasOwnProperty('enables')) {
inputToggle(input);
}
break;
default:
input.value = opts[key];
Expand Down Expand Up @@ -86,6 +111,15 @@ window.addEventListener('DOMContentLoaded', async () => {
});
});

$('[data-enables]', form).forEach(field => {
const proxChangeHandler = proxyEvent(field);
field.addEventListener('change', inputToggle);
const proxies = $(`[name="${field.name}"]:not([data-enables="${field.dataset.enables}"])`, form);
proxies.forEach(proxy => {
proxy.addEventListener('change', proxChangeHandler);
});
});

$('[data-locale-text]', form).forEach(getText);
$('[data-locale-title]', form).forEach(getTitle);
$('[data-locale-placeholder]', form).forEach(getPlaceholder);
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Chris Zuber",
"url": "https://shgysk8zer0.github.io"
},
"version": "1.3.0",
"version": "1.3.1",
"description": "__MSG_extensionDescription__",
"homepage_url": "https://github.com/shgysk8zer0/awesome-rss",
"icons": {
Expand Down
29 changes: 28 additions & 1 deletion options.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</label>
<input type="radio" name="service" value="feedly" id="subscribe-feedly" />
<label for="subscribe-feedly" class="browser-style-label" title="Subscribe using Feedly" data-locale-title="feedlySubscribe">
<svg class="icon" width="32" height="32">
<svg class="icon" width="60" height="32">
<use xlink:href="icons.svg#feedly" />
</svg>
<span>Feedly</span>
Expand All @@ -46,6 +46,33 @@
</svg>
<span>Inoreader</span>
</label>
<input type="radio" name="service" id="subscribe-nextcloud" value="nextcloud" data-enables="nextcloudUrl">
<label for="subscribe-nextcloud" class="browser-style-label">
<svg class="icon" height="32" width="60">
<use xlink:href="icons.svg#nextcloud" />
</svg>
<span>NextCloud</span>
</label>
<input type="radio" name="service" id="subscribe-tiny-tiny-rss" value="tinyTinyRss" data-enables="tinyTinyRssUrl">
<label for="subscribe-tiny-tiny-rss" class="browser-style-label">
<svg class="icon" width="32" height="32">
<use xlink:href="icons.svg#tiny-tiny-rss" />
</svg>
<span>TinyTinyRSS</span>
</label>
<br />
<label for="nextcloud-url" hidden="">
<svg class="icon" width="32">
<use xlink:href="icons.svg#link" />
</svg>
</label>
<input name="nextcloudUrl" id="nextcloud-url" type="url" placeholder="https://nextcloud-server.com" disabled="" hidden="" />
<label for="tiny-tiny-rss-url" hidden="">
<svg class="icon" width="32">
<use xlink:href="icons.svg#link" />
</svg>
</label>
<input name="tinyTinyRssUrl" id="tiny-tiny-rss-url" type="url" placeholder="https://ttrss-server.com" disabled="" hidden="" />
</fieldset>
<fieldset>
<legend data-locale-text="popupOptionsLegend">Popup Options</legend>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "awesome-rss",
"version": "1.3.0",
"version": "1.3.1",
"description": "Puts an RSS/Atom subscribe button back in URL bar",
"keywords": [
"WebExtension",
Expand Down

0 comments on commit 7cbe971

Please sign in to comment.