Steam Inventory Preview Background Button

Add preview background button to steam inventory.

  1. // ==UserScript==
  2. // @name Steam Inventory Preview Background Button
  3. // @namespace http://steamcommunity.com/profiles/76561197995708004/
  4. // @version 1.02
  5. // @description Add preview background button to steam inventory.
  6. // @author HAC
  7. // @match http://steamcommunity.com/profiles/*
  8. // @match http://steamcommunity.com/id/*
  9. // @grant none
  10. // @license GPLv3
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. let path = window.location.pathname.replace(/\/+/g, "/");
  17. if(/^\/(?:id|profiles)\/.+\/inventory/.test(path)) {
  18. let observer = new MutationObserver(function(mutations) {
  19. let activeItemInfo = iActiveSelectView; // Get iActiveSelectView from global
  20. inventoryAddButtonPreviewBackground(activeItemInfo);
  21. });
  22. observer.observe(document.getElementById('iteminfo0_item_name'), { childList: true });
  23. observer.observe(document.getElementById('iteminfo1_item_name'), { childList: true });
  24. } else if(/^\/(?:id|profiles)\/.+/.test(path)){
  25. let previewHash = window.location.hash.match(/#previewBackground\/(\d+\/[a-z0-9]+(?:\.[a-z0-9]+)?)/i);
  26. if (previewHash) {
  27. let imageUrl = window.location.protocol + '//steamcdn-a.akamaihd.net/steamcommunity/public/images/items/' + previewHash[1];
  28. profileChangeBackground(imageUrl);
  29. }
  30. }
  31.  
  32. function inventoryAddButtonPreviewBackground (activeItemInfo){
  33. let profileUrlNodesWrapper = document.getElementById('global_actions');
  34. let profileUrlNodes = profileUrlNodesWrapper.getElementsByClassName('playerAvatar');
  35. let profileUrl = profileUrlNodes[0].href;
  36. let itemButtonsHolder = document.getElementById('iteminfo' + activeItemInfo + '_item_actions');
  37. let itemButtons = itemButtonsHolder.getElementsByTagName('a');
  38. let imageUrl = itemButtons[0].href;
  39. let imageUrlMatch = imageUrl.match(/images\/items\/(\d+\/[a-z0-9]+(?:\.[a-z0-9]+)?)/i);
  40. if(imageUrlMatch !== null) {
  41. imageUrlMatch = imageUrlMatch[1];
  42. let previewUrl = profileUrl + '#previewBackground/' + imageUrlMatch;
  43.  
  44. let a = document.createElement('a');
  45. a.setAttribute('href', previewUrl);
  46. a.setAttribute('target', '_blank');
  47. a.classList.add('btn_small');
  48. a.classList.add('btn_darkblue_white_innerfade');
  49. itemButtonsHolder.appendChild(a);
  50. let span = document.createElement('span');
  51. span.textContent = 'Preview Background';
  52. a.appendChild(span);
  53. itemButtonsHolder.style.height = '';
  54. }
  55. }
  56.  
  57. function profileChangeBackground(imageUrl) {
  58. let img = document.createElement('img');
  59. img.style.display = 'none';
  60. img.src = imageUrl;
  61. document.body.appendChild(img);
  62. img.onload = function() {
  63. let bgImgNodes = document.getElementsByClassName('no_header profile_page');
  64. for(let bgImgNode of bgImgNodes) { bgImgNode.style.backgroundImage = 'url(' + imageUrl + ')'; }
  65. let bgImgNodes2 = document.getElementsByClassName('profile_background_image_content');
  66. for(let bgImgNode2 of bgImgNodes2) { bgImgNode2.style.backgroundImage = 'url(' + imageUrl + ')'; }
  67. img.remove();
  68. };
  69. img.onerror = function() {
  70. console.log("Error: Can't load image. " + imageUrl);
  71. img.remove();
  72. };
  73. }
  74. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址