-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.php
46 lines (38 loc) · 1.07 KB
/
init.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
class Remember_Previous extends Plugin {
function about() {
return [
1.5, // version
'Remember your last-viewed category or feed.', // description
'wn', // author
false, // is system
'https://www.github.com/supahgreg/ttrss-remember-previous', // more info URL
];
}
function api_version() {
return 2;
}
function init($host) {
}
function get_js() {
return <<<'JS'
require(['dojo/ready'], (ready) => {
ready(() => {
const COOKIE_NAME = 'remember_previous';
// Set our cookie when the active feed changes
PluginHost.register(PluginHost.HOOK_FEED_SET_ACTIVE, ([aId,aIsCategory]) => {
Cookie.set(COOKIE_NAME, aId + "," + (aIsCategory ? 1 : 0), 604800); // 1 week
});
PluginHost.register(PluginHost.HOOK_PARAMS_LOADED, () => {
let prev = Cookie.get(COOKIE_NAME);
if (/^-?\d+,[01]$/.test(prev)) {
console.log(`[Remember_Previous] restoring category or feed: ${prev}`);
prev = prev.split(',');
App.Hash.set({f: prev[0], c: prev[1]});
}
});
});
});
JS;
}
}