-
Notifications
You must be signed in to change notification settings - Fork 14
Contributing
Thank you for considering to contribute to SOX!
Please follow the following steps when adding a new feature:
- Write a function that implements the feature
- Add it to the bottom of the
featuresobject insox.features.js. It's name should be in camelCase - Add the feature to
sox.features.info.json. Please put it under the most fitting category (eg. underAppearance). The following fields must be included: -
name: the camelCase ID of the function you added to sox.features.js -
desc: a short description of the feature you're adding, which will be displayed in the control panel -
meta: a URL linking to a meta post if that is where you got the idea from/were trying to fix, or"" -
match: a string of comma-separated match patterns for URLs where the feature should run on -
exclude: a string of comma-separated match patterns for URLs where the feature should run on, or"" - Any CSS should be added to
sox.css, with a comment before it indicating which feature it is for. CSS rules should ideally be prepended with the function ID (the camelCase name).
##Helper functions
SOX has various helper functions and getters you can use to get information:
-
sox.debug(message, [message2, message3, ...]): doesconsole.debugto the console, prepended withSOX:. Only logs if user has enabled debugging -
sox.log(message, [message2, message3, ...]): doesconsole.log, prepended withSOX:. -
sox.warn(message, [message2, message3, ...]): doesconsole.warn, prepended withSOX:. -
sox.error(message, [message2, message3, ...]): doesconsole.error, prepended withSOX:. -
sox.loginfo(message, [message2, message3, ...]): doesconsole.info, prepended withSOX:. -
sox.settings.accessToken: returns the user's access token; you shouldn't need to use this, becaues thesox.helpers.getFromAPI()function (below) should allow you to use the API with the access token itself -
sox.helpers.getFromAPI(type, id, sitename, filter, callback, sortby): sends a AJAX GET request to the API with the typetypewith idid(comma seperated if more than one) on sitesitename, passing the data back tocallback.sortbyis optional. -
sox.helpers.observe(elements, callback, toObserve): sets up a MutationObserver to callcallback(passing the mutated elements) if any element in the jQueryelementsobject is mutated.toObserveis optional and can be used to specify which part of the page to watch for mutations in -
sox.site.id: get the current site ID -
sox.site.name: get the current site's name -
sox.site.type: get the current site's type (beta/main/meta/chat) -
sox.site.url: get the current page's hostname -
sox.site.href: get the current page's URL -
sox.site.apiParameter(siteName): get the site parameter for a givensiteName(retrieved withsox.site.name) -
sox.site.CurrentApiParameter(siteName): returns the current site's API parameter -
sox.location.on(location): returnstrueif the current page's URL matches a givenlocationstring (internally usesindexOf) -
sox.location.onUserProfile: returnstrueif the user is currently on a user profile -
sox.location.onQuestion: returnstrueif the user is currently on a question page -
sox.location.match(matchPattern): returns true if the current page matches a given [matchPattern'](https://developer.chrome.com/extensions/match_patterns).SE1.0` is a special pattern which checks for whether the current site is either Area51 or the main Stack Exchange site. -
sox.user.id: returns the current user's ID -
sox.user.rep: returns the current' user's reputation level -
sox.user.name: returns the current user's username -
sox.user.loggedIn: returnstrueif the user is logged in -
sox.user.hasPrivilege(privilege): returnstrueif the current user has enough reputation to have a certainprivilege(this is a string, and is the privilege name you see on the main privileges page)
##Testing locally
To test locally, simply create a userscript which //@require's the local version of your files. Here's a template that you can modify to work for your system:
// ==UserScript==
// @name Local SOX
// @match *://*.stackoverflow.com/*
// @match *://*.stackexchange.com/*
// @match *://*.superuser.com/*
// @match *://*.serverfault.com/*
// @match *://*.askubuntu.com/*
// @match *://*.stackapps.com/*
// @match *://*.mathoverflow.net/*
// @match *://github.com/soscripted/*
// @match *://soscripted.github.io/sox/*
// @exclude *://data.stackexchange.com/*
// @exclude *://api.stackexchange.com/*
// @require https://code.jquery.com/jquery-3.3.1.min.js
// @require https://code.jquery.com/ui/1.12.1/jquery-ui.min.js
// @require https://api.stackexchange.com/js/2.0/all.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.5.3/jquery.timeago.min.js
// @require file:///C:/User/Github/sox/sox.common.js
// @require file:///C:/User/Github/sox/sox.github.js
// @require file:///C:/User/Github/sox/sox.dialog.js
// @require file:///C:/User/Github/sox/sox.enhanced_editor.js
// @require file:///C:/User/Github/sox/sox.features.js
// @require file:///C:/User/Github/sox/sox.user.js
// @resource css file:///C:/User/Github/sox/sox.css
// @resource dialog file:///C:/User/Github/sox/sox.dialog.html
// @resource featuresJSON file:///C:/User/Github/sox/sox.features.info.json
// @resource common file:///C:/User/Github/sox/sox.common.info.json
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant GM_info
// ==/UserScript==
Make sure Tampermonkey/Greasemonkey has been allowed access to local file URLs!