Displays the number of volunteer credits for parkrun finishers on results pages, for celebration purposes (and let's not make assumptions about ratios)

What is a userscript?

A userscript is a small piece of JavaScript that runs in your browser and enhances specific websites. These scripts work with parkrun event pages, parkrunner profile pages, and results pages, and can be used with any userscript manager including Userscripts, Tampermonkey, Violentmonkey, or any compatible browser extension.

Installation

  1. Install a userscript manager for your browser:
  2. Click the install link below for this script.
  3. Click “Install” when prompted by your userscript manager.

parkrun Volunteer Days Display Screenshot

Install parkrun Volunteer Days Display

Bookmarklet version

You can also use this script as a bookmarklet (a bookmark whose URL is JavaScript), which can be useful on browsers that support bookmarks but not userscript managers.

Desktop bookmarklet

Drag this link to your bookmarks bar:

parkrun Volunteer Days Display bookmarklet

Mobile bookmarklet

On mobile browsers that let you edit bookmark URLs:

  1. Copy the JavaScript code below to your clipboard.
  2. Create a new bookmark for any page.
  3. Edit the bookmark and replace its URL with the code you copied.
  4. Navigate to the relevant parkrun page.
  5. Select the bookmark to run the script.
javascript:(function(){!function e(){var t,s,a,o,n,l,r,c;function d(e){i(e),s.querySelectorAll(".Results-dialog-option.js-ResultsOption").forEach(function(e){return e.classList.remove("isSelected")}),s.querySelectorAll(".Results-dialog-arrow.js-ResultsDirection").forEach(function(e){return e.classList.remove("isSelected")}),a.classList.add("isSelected"),("asc"===e?l:r).classList.add("isSelected")}function i(o){var e;t&&((e=Array.from(t.querySelectorAll("tr")).map(function(e,t){return{row:e,index:t}})).sort(function(e,t){var s=parseInt(e.row.getAttribute("data-vols")||"0",10),a=parseInt(t.row.getAttribute("data-vols")||"0",10);return s===a?e.index-t.index:"asc"===o?s-a:a-s}),e.forEach(function(e){return e=e.row,t.appendChild(e)}))}document.querySelector("tr[data-vols]")?(document.querySelectorAll("tr[data-vols] > td.Results-table-td.Results-table-td--name > div.detailed").forEach(function(e){var t,s,a=e.closest("tr").getAttribute("data-vols");a&&0<parseInt(a)&&((t=document.createElement("span")).classList.add("spacer"),t.textContent=" | ",(s=document.createElement("span")).textContent="".concat(a," volunteer credit").concat("1"===a?"":"s"),s.classList.add("volunteer-days"),(a=e.querySelector(".Results-tablet"))?(e.insertBefore(t,a),t.insertAdjacentElement("afterend",s)):(a=e.firstElementChild)?(a.insertAdjacentElement("afterend",t),t.insertAdjacentElement("afterend",s)):e.appendChild(s))}),(c=document.querySelector("tr[data-vols]"))&&(t=c.closest("tbody"),(c=document.querySelector('select[name="sort"], .Results-sort select, select.Results-sort, .Results-controls select'))&&(c.querySelector('option[value="vols-asc"]')||(o=new Option("Sort by volunteer credits ▲","vols-asc"),n=new Option("Sort by volunteer credits ▼","vols-desc"),c.appendChild(o),c.appendChild(n)),c.dataset.volsSortWired||(c.addEventListener("change",function(e){var t=e.target.value||"";"vols-asc"!==t&&"vols-desc"!==t||(e.cancelable&&e.preventDefault(),"function"==typeof e.stopImmediatePropagation&&e.stopImmediatePropagation(),"function"==typeof e.stopPropagation&&e.stopPropagation(),i(t.endsWith("asc")?"asc":"desc"))},!0),c.addEventListener("change",function(e){"vols-asc"===(e=e.target.value||"")?i("asc"):"vols-desc"===e&&i("desc")}),c.dataset.volsSortWired="true")),s=document.querySelector('.Results-dialog-options[data-name="sort"]'))&&!s.querySelector('[data-vols-sort="true"]')&&((a=document.createElement("div")).className="Results-dialog-option Results-dialog-option--block js-ResultsOption",a.dataset.volsSort="true",(o=document.createElement("button")).type="button",o.className="Results-dialog-button",(n=document.createElement("span")).textContent="Sort by volunteer credits",o.appendChild(n),(c=document.createElement("div")).className="Results-dialog-arrows",(l=document.createElement("button")).type="button",l.className="Results-dialog-arrow js-ResultsDirection",l.dataset.value="vols-asc",l.textContent="▲",(r=document.createElement("button")).type="button",r.className="Results-dialog-arrow js-ResultsDirection",r.dataset.value="vols-desc",r.textContent="▼",l.addEventListener("click",function(e){e.cancelable&&e.preventDefault(),e.stopPropagation(),d("asc")}),r.addEventListener("click",function(e){e.cancelable&&e.preventDefault(),e.stopPropagation(),d("desc")}),c.appendChild(l),c.appendChild(r),a.appendChild(o),a.appendChild(c),s.appendChild(a))):setTimeout(e,500)}();})()
Last updated
Version
1.1.8
Author
Pete Johns (@johnsyweb)
Homepage
https://www.johnsy.com/tampermonkey-parkrun/
Support
Issues / support
License
MIT