Last active
July 7, 2021 21:18
-
-
Save niikoo/0a86f8cd0b71c971f2284f04cf75a3f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name SAS EuroBonus Online Shopping - Sort by points descending | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1.3 | |
// @description Sorting the points | |
// @author niikoo | |
// @match https://onlineshopping.flysas.com/* | |
// @icon https://icons.duckduckgo.com/ip2/flysas.com.ico | |
// @updateURL https://gist.github.com/niikoo/0a86f8cd0b71c971f2284f04cf75a3f2/raw/sas-eurobonus-online-shopping-pointsort.user.js | |
// @downloadURL https://gist.github.com/niikoo/0a86f8cd0b71c971f2284f04cf75a3f2/raw/sas-eurobonus-online-shopping-pointsort.user.js | |
// @grant none | |
// ==/UserScript== | |
/* global $ */ | |
(function() { | |
'use strict'; | |
// Turn points into sort placing | |
var $list = $('main > div.Container > div.ShopGrid'); | |
if($list != null) { | |
$('>div', $list).each(function() { | |
var points = +[].reduce.call($(this).find('span.PointsHighlight')[0].childNodes, function(a, b) { return a + (b.nodeType === 3 ? b.textContent : ''); }, '').replace(/\s/, '').trim(); | |
$(this).find('a').attr('title', "Tilsvarer " + Math.round(points / 13.5) + " trumf kr/poeng (kurs: 13,5)"); | |
$(this).data('sort', points); | |
}); | |
// Sort divs | |
var result = $('>div', $list).sort(function (b, a) { | |
var contentA =parseInt( $(a).data('sort')); | |
var contentB =parseInt( $(b).data('sort')); | |
return (contentA < contentB) ? -1 : (contentA > contentB) ? 1 : 0; | |
}); | |
$list.html(result); | |
console.log('Cards are sorted after points, descending.'); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment