Skip to content

Contributing

ᔕᖺᘎᕊ edited this page Dec 20, 2016 · 13 revisions

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 features object in sox.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. under Appearance). The following fields should be used:
  • name: required, the camelCase ID of the function you added to sox.features.js
  • desc: required, 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
  • 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
  • Any CSS should be added to sox.css, with a comment before it indicating which feature it is for. CSS rules should 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.helpers.notify(message): log to the console, prepended with SOX:

  • 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 given siteName (retrieved with sox.site.name)

  • sox.location.on(location): returns true if the current page's URL matches a given location string (internally uses indexOf)

  • sox.location.onUserProfile: returns true if the user is currently on a user profile

  • sox.location.onQuestion: returns true if the user is currently on a question page

  • sox.location.match(matchPattern): returns true if the current page matches a given `matchPattern'

  • 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: returns true if the user is logged in

  • sox.user.hasPrivilege(privilege): returns true if the current user has enough reputation to have a certain privilege (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-2.1.4.min.js
// @require      https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js
// @require      https://api.stackexchange.com/js/2.0/all.js
// @require      https://cdn.rawgit.com/timdown/rangyinputs/master/rangyinputs-jquery-src.js
// @require      https://cdn.rawgit.com/jeresig/jquery.hotkeys/master/jquery.hotkeys.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!

Clone this wiki locally