Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sergiosusa/d73086b7869e1f0024cb9ae07e796843 to your computer and use it in GitHub Desktop.
Save sergiosusa/d73086b7869e1f0024cb9ae07e796843 to your computer and use it in GitHub Desktop.
Add an option to organize the showcases movind up and down
// ==UserScript==
// @name Steam Profile Showcase Organizer
// @namespace http://sergiosusa.com
// @version 0.1
// @description Add some features to the profile edit page on Steam.
// @author Sergio Susa ([email protected])
// @match https://steamcommunity.com/id/*/edit
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
$.noConflict();
jQuery( document ).ready(function() {
insertGraphicElements();
bindEventsToElements();
});
})();
function insertGraphicElements()
{
var controls = jQuery(".customization_controls");
jQuery.each(controls, function(index, item){
var html = '<a id="showcase_down" href="#" class="btn_grey_black btn_medium down_btn"><span>Down &darr;</span></a>' +
'<a id="showcase_up" href="#" class="btn_grey_black btn_medium up_btn"><span>Up &uarr;</span></a>';
var newElement = document.createElement('span');
newElement.innerHTML = html;
item.appendChild(newElement);
});
}
function bindEventsToElements()
{
var upBtns = jQuery(".down_btn");
jQuery.each(upBtns, function(index, btn){
btn.onclick = downShowcase;
});
var downBtns = jQuery(".up_btn");
jQuery.each(downBtns, function(index, btn){
btn.onclick = upShowcase;
});
}
function upShowcase(event)
{
showcaseContainer = this.parentNode.parentNode.parentNode.parentNode;
showcase = this.parentNode.parentNode.parentNode;
if (showcase.previousElementSibling.className == "formRow"){
showcaseContainer.insertBefore(showcase, showcase.previousElementSibling.previousElementSibling);
} else {
showcaseContainer.insertBefore(showcase, showcase.previousElementSibling);
}
event.preventDefault();
}
function downShowcase(event)
{
showcaseContainer = this.parentNode.parentNode.parentNode.parentNode;
showcase = this.parentNode.parentNode.parentNode;
if (showcase.nextSibling == null){
showcaseContainer.insertBefore(showcase, showcaseContainer.firstChild.nextElementSibling.nextElementSibling);
} else {
showcaseContainer.insertBefore(showcase, showcase.nextElementSibling.nextElementSibling);
}
event.preventDefault();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment