User:Lectrician1/sort-values.js

From Wikidata
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// I don't know if this works. haven't tested it in awhile.

(function () {
	"use strict";
	"esversion: 9";

	// When the page has rendered
	mw.hook("wikibase.entityPage.entityView.rendered").add(function () {

		// When the entity has rendered
		mw.hook("wikibase.entityPage.entityLoaded").add(function (entity) {

			for (var claim in entity.claims) {
				if (entity.claims[claim].length > 1) {
					if (entity.claims[claim][0].mainsnak.datatype == "monolingualtext") {
						$(`#${claim} .wikibase-statementgroupview-property-label`).append(
							`<form>
								<label for="cars">Sort:</label>
								<select name="cars" id="cars">
									<option value="ascending"></option>
									<option value="ascending">Ascending</option>
									<option value="descending">Descending</option>
								</select>
							</form>
							<script src="https://cdnjs.cloudflare.com/ajax/libs/tinysort/3.2.5/tinysort.min.js"></script>
							`
						);
						
						tinysort('.wb-monolingualtext-value>div', );
						
					}
				}
			}

		});

	});

})();