PS Store Subscription Links Locale Fix

This script fixes the issue that the PS Plus and EA Play links on the PS Store subscriptions page do not have a locale set.

  1. // ==UserScript==
  2. // @name PS Store Subscription Links Locale Fix
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description This script fixes the issue that the PS Plus and EA Play links on the PS Store subscriptions page do not have a locale set.
  6. // @author Nathaniel Wu
  7. // @include *store.playstation.com/*
  8. // @license Apache-2.0
  9. // @supportURL https://gist.github.com/Nathaniel-Wu/2ff7fe939acca362d7fdeaf17b4f0d18
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. const in_iframe = () => {
  16. try {
  17. return window.self !== window.top;
  18. } catch (e) {
  19. return true;
  20. }
  21. }
  22. if (!in_iframe()) {
  23. const onSubscriptionPage = () => {
  24. return /^https?:\/\/store\.playstation\.com\/[^\/]+\/pages\/subscriptions($|\/)/g.test(window.location.href) || /^https?:\/\/store\.playstation\.com\/[^\/]*\/view\/[^\/]+\/[^\/]+\/?$/.test(window.location.href);
  25. };
  26. const fixSubscriptionLinks = () => {
  27. const locale = window.location.href.replace(/^https?:\/\/store\.playstation\.com\/([^\/]+)\/(.+)?$/g, '$1');
  28. document.querySelectorAll('.psw-solid-link.psw-button.psw-primary-button.psw-solid-button').forEach(e => {
  29. if (/(\/|\.)playstation\.com\/ps-plus($|\/)/g.test(e.href)) {
  30. // Fix the PS Plus link
  31. e.href = e.href.replace(/((\/|\.)playstation\.com\/)ps-plus/g, `$1${locale}/ps-plus`);
  32. } else if (/(\/|\.)playstation\.com\/eaplay($|\/)/g.test(e.href)) {
  33. // Fix the EA Play link
  34. e.href = e.href.replace(/((\/|\.)playstation\.com\/)eaplay/g, `$1${locale}/games/ea-play`);
  35. } else if (/(\/|\.)playstation\.com\/games\/ubisoft-plus-classics($|\/)/g.test(e.href)) {
  36. // Fix the Ubisoft Plus Classics link
  37. e.href = e.href.replace(/((\/|\.)playstation\.com\/)games\/ubisoft-plus-classics/g, `$1${locale}/games/ubisoft-plus-classics`);
  38. }
  39. });
  40. };
  41. if (onSubscriptionPage())
  42. fixSubscriptionLinks()
  43. let activeTransitions = 0;
  44. document.addEventListener('transitionend', (e) => {
  45. activeTransitions++;
  46. setTimeout(() => {
  47. activeTransitions--;
  48. if (activeTransitions == 0 && onSubscriptionPage())
  49. fixSubscriptionLinks();
  50. }, 200);
  51. });
  52. }
  53. })();