diff --git a/opforumtools.user.js b/opforumtools.user.js
index 209353a..c7d35b6 100644
--- a/opforumtools.user.js
+++ b/opforumtools.user.js
@@ -1,168 +1,313 @@
-// ==UserScript==
-// @name OnePlus Forum Tools
-// @namespace *.oneplus.net*
-// @version 2.0.0
-// @description Useful sidebar addon for the OnePlus forum! :)
-// @author github.com/kpsuperplane, github.com/rag3trey
-// @include *forums.oneplus.net*
-// @grant none
-// @license MIT License; http://opensource.org/licenses/MIT
-// @require https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js
-// ==/UserScript==
+ // ==UserScript==
+ // @name OnePlus Forum Tools
+ // @namespace *.oneplus.net*
+ // @version 2.0.1
+ // @description Useful sidebar addon for the OnePlus forum! :)
+ // @author github.com/kpsuperplane, github.com/rag3trey
+ // @include *forums.oneplus.net*
+ // @grant none
+ // @license MIT License; http://opensource.org/licenses/MIT
+ // @require https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js
+ // ==/UserScript==
-window.define = define;
-window.require = require;
+ window.define = define;
+ window.require = require;
-window.nativeAsset = function(path) {
- return `https://rawgit.com/rag3trey/Forum-Tools-2.0/master/${path}`;
-};
+ window.nativeAsset = function(path) {
+ return `https://cdn.rawgit.com/rag3trey/Forum-Tools-2.0/2.0.1/${path}`;
+ };
-requirejs.config({
- paths: {
- "Vue": "https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.1/vue.min",
- "vue": "https://rawgit.com/edgardleal/require-vue/master/dist/require-vuejs"
- },
- shim: {
- "Vue": {"exports": "Vue"}
- },
- map: {
- '*': {
- 'css': 'https://cdnjs.cloudflare.com/ajax/libs/require-css/0.1.10/css.min.js' // or whatever the path to require-css is
+ requirejs.config({
+ paths: {
+ "Vue": "https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.1/vue.min"
+ },
+ shim: {
+ "Vue": {"exports": "Vue"}
+ },
+ map: {
+ '*': {
+ 'css': 'https://cdnjs.cloudflare.com/ajax/libs/require-css/0.1.10/css.min.js' // or whatever the path to require-css is
+ }
}
- }
-});
+ });
-require(['https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js', `css!${nativeAsset('spectre/dist/spectre.min')}`, `css!${nativeAsset('spectre/dist/spectre-icons.min')}`], (_) => {
-
- class ConfigModule{
- constructor(name, defaultConfig, _tools) {
- this._config = null;
- this.name = name;
- this.defaultConfig = defaultConfig;
- this._tools = _tools;
- }
- getConfig() {
- if (this._config === null) {
- this._config = this._tools.setConfig(_.merge({modules: {
- [this.name]: {
- config: _.mapValues(this.defaultConfig, 'default')
+ require(['https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js', `css!${nativeAsset('spectre/dist/spectre.min')}`, `css!${nativeAsset('spectre/dist/spectre-icons.min')}`], (_) => {
+
+ class ConfigModule{
+ constructor(name, manifest, _tools) {
+ this._config = null;
+ this.name = name;
+ this.defaultConfig = manifest.config;
+ this.manifest = manifest;
+ this._tools = _tools;
+ this.getConfig();
+ }
+ setConfig(config) {
+ this._tools.setConfig({
+ modules: {
+ [this.name]: {
+ config: config
+ }
}
- }}, this._tools.getConfig())).modules[this.name].config;
+ });
+ }
+ getConfig() {
+ if (this._config === null) {
+ const mergedConfigs = _.merge({modules: {
+ [this.name]: {
+ config: _.mapValues(this.defaultConfig, 'default')
+ }
+ }}, this._tools.getConfig());
+ mergedConfigs.modules[this.name].manifest = this.manifest;
+ this._config = this._tools.overrideConfig(mergedConfigs).modules[this.name].config;
+ }
+ return this._config;
}
- return this._config;
}
- }
- class ForumTools {
- setConfig(config) {
- window.localStorage.setItem('forumTools', JSON.stringify(config));
- return config;
+ class ForumTools {
+ overrideConfig(config) {
+ window.localStorage.setItem('forumTools', JSON.stringify(config));
+ return config;
+ }
+ setConfig(config) {
+ return this.overrideConfig(_.merge(JSON.parse(window.localStorage.getItem('forumTools')), config));
+ }
+ getConfig(forceLoad = false) {
+ const config = this.config || JSON.parse(window.localStorage.getItem('forumTools'));
+ return config || this.setConfig({
+ modules: {
+ configurator: {
+ config: {},
+ enabled: true
+ },
+ general: {
+ config: {},
+ enabled: true
+ }
+ }
+ });
+ }
+ toggleModule(name) {
+ this.setConfig({modules: {
+ [name]: {
+ enabled: !this.getConfig().modules[name].enabled
+ }
+ }});
+ }
+ module(name, deps, manifest, init) {
+ const ctx = new ConfigModule(name, manifest, this);
+ define(name, deps, init.bind(ctx));
+ }
+ init() {
+ require(_.keys(_.pickBy(this.getConfig().modules, (val) => val.enabled)));
+ }
+ constructor() {
+ this.debug = true;
+ this.config = null;
+ this._modules = {};
+ }
}
- getConfig(forceLoad = false) {
- const config = this.config || JSON.parse(window.localStorage.getItem('forumTools'));
- return config || this.setConfig({
- modules: {
- configurator: {
- config: {},
- enabled: true
+
+ window.forumTools = new ForumTools();
+
+ // GUI Configuration Module
+ forumTools.module('configurator', ['Vue'], {
+ name: "Configurator",
+ description: "Default configuration module for the OnePlus Forum Tools.",
+ config: {}
+ }, function(Vue){
+ const navItem = $(`
+ Tools
+ `);
+ const configMenu = $(`
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Hi there! Welcome to forum tools
+
This script exists because @Baymax wanted it. @kp1234 came to the rescue. Yay!
+
+
+
+
{{modules[tab].manifest.name}}
+
+
+
This module cannot be disabled.
+
Description
+
{{modules[tab].manifest.description}}
+
Module Configuration
+
+
This module has no settings
+
+
+
You may need to refresh for changes to take effect
+
+
+
+
+
+
+
+
+
`);
+ $('.sticky-wrapper').css({'position': 'relative', 'z-index': '100'});
+ $('#header-nav-top .nav:first').append(navItem);
+ $('#header-nav-top .row:first').css('z-index', '2');
+ $('#header-nav-top').append(configMenu);
+ var app = new Vue({
+ el: configMenu[0],
+ data: {
+ active: false,
+ tab: null,
+ dirty: false,
+ whitelist: ['configurator'],
+ modules: _.cloneDeep(forumTools.getConfig().modules)
+ },
+ methods: {
+ toggle: function() {
+ this.active = !this.active;
+ },
+ toggleModule: function(name) {
+ forumTools.toggleModule(name);
+ this.reload();
+ },
+ makeDirty: function() {
+ this.dirty = true;
+ },
+ changeTab: function(tab) {
+ this.dirty = false;
+ this.tab = tab;
+ },
+ save: function() {
+ if (this.tab != null) {
+ this.modules = _.cloneDeep(forumTools.setConfig({
+ modules: {
+ [this.tab]: {
+ config: this.modules[this.tab].config
+ }
+ }
+ }).modules);
+ this.dirty = false;
+ }
+ },
+ reload: function() {
+ this.modules = _.cloneDeep(forumTools.getConfig(true).modules);
+ this.dirty = false;
}
}
});
- }
- _addModule(name, manifest) {
- this._modules[name] = manifest;
- }
- getModules() {
- return this._modules;
- }
- module(name, deps, manifest, init) {
- manifest.config = new ConfigModule(name, manifest.config, this);
- this._addModule(name, manifest);
- define(name, deps, init.bind(manifest.config));
- }
- init() {
- require(_.keys(this.getConfig().modules));
- }
- constructor() {
- this.debug = true;
- this.config = null;
- this._modules = {};
- }
- }
-
- window.forumTools = new ForumTools();
+ navItem.click(() => app.toggle());
- // GUI Configuration Module
- forumTools.module('configurator', ['Vue'], {
- name: "Configurator",
- config: {}
- }, function(Vue){
+ });
- const navItem = $(`
- Tools
- `);
- const configMenu = $(`
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Hi there! Welcome to forum tools
-
This script exists because @Baymax wanted it. @kp1234 came to the rescue. Use it to install plugins into the forum. Yay!
-
-
Need something?
-
-
-
-
-
-
-
-
-
-
-
-
-
`);
- $('.sticky-wrapper').css({'position': 'relative', 'z-index': '100'});
- $('#header-nav-top .nav:first').append(navItem);
- $('#header-nav-top .row:first').css('z-index', '2');
- $('#header-nav-top').append(configMenu);
- var app = new Vue({
- el: configMenu[0],
- data: {
- active: false,
- modules: forumTools.getModules()
- },
- methods: {
- toggle: function() {
- this.active = !this.active;
+ // GUI Configuration Module
+ forumTools.module('general', [], {
+ name: "General",
+ description: "Default module for the OnePlus Forum Tools that does general stuff.",
+ config: {
+ homepage: {
+ type: 'select',
+ options: [
+ {title: "None", value: "none"},
+ {title: "Recent", value: "recent"},
+ {title: "Recommended", value: "recommend"},
+ {title: "Most Viewed", value: "hot"},
+ {title: "Most Liked", value: "popular"}
+ ],
+ label: 'Default Homepage',
+ default: "none"
+ },
+ links: {
+ type: 'textarea',
+ label: 'Quick Links (one per line)',
+ default: "Wormhole: Unread -> /threads/wormhole.269956/unread"
}
}
- });
- navItem.click(() => app.toggle());
+ }, function(){
+ const config = this.getConfig();
- });
+ // Homepage defaults
+ (() => {
+ if (config.homepage != "none") {
+ const homeUri = `https://forums.oneplus.net?order=${config.homepage}`;
+ if (location.href.match(/https:\/\/forums.oneplus.net\/?$/g)) location.href=homeUri;
+ $('#header-nav-top a[href="/"]').attr('href', homeUri);
+ }
+ })();
- forumTools.init();
+ // Quick links
+ ((links) => {
+ if (links[0][0] != "") {
+ const linkContainer = $('Quick Links
').css({
+ position: 'absolute',
+ left: '63px',
+ borderBottomLeftRadius: '3px',
+ borderBottomRightRadius: '3px',
+ padding: '4px 10px',
+ background: '#e5e5e6',
+ bottom: '10px'
+ });
+ for (const link of links) {
+ $('').attr('href', link[1]).text(link[0]).css({
+ marginLeft: '10px',
+ color: 'rgb(235,0,40)'
+ }).appendTo(linkContainer);
+ }
+ $('#header-nav-top').append(linkContainer);
+ }
+ })(config.links.split('\n').map(v => v.split('->').map(s => s.trim())));
+ });
+ forumTools.init();
-});
\ No newline at end of file
+ });
\ No newline at end of file