Sleazy Fork is available in English.

MyNSLC Age Saver

Saves date of birth information to bypass the age verification page on the Cannabis MyNSLC site.

  1. // ==UserScript==
  2. // @name MyNSLC Age Saver
  3. // @namespace https://github.com/Fawrsk/MyNSLC-Age-Saver
  4. // @version 1.0.2
  5. // @description Saves date of birth information to bypass the age verification page on the Cannabis MyNSLC site.
  6. // @author Fawrsk
  7. // @match https://cannabis.mynslc.com/skins/Cannabis/pages/VerifyAge.aspx
  8. // @grant none
  9. // @license MIT
  10. // @run-at document-end
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. /**
  17. * The key used for localStorage.
  18. */
  19. const STORAGE_ITEM_KEY = 'faw_dob';
  20.  
  21. /**
  22. * How long the script should wait for the UI to update after clicking the
  23. * verify button.
  24. */
  25. const ERROR_VISIBILITY_TIMEOUT = 500;
  26.  
  27. /**
  28. * Throws an error with the message provided.
  29. * @param {string} msg
  30. */
  31. function error(msg) {
  32. if (typeof msg !== 'string') {
  33. msg = 'Unknown error.';
  34. }
  35.  
  36. throw new Error(msg);
  37. }
  38.  
  39. /**
  40. * Returns an element by a query selector or can throw an error if nothing
  41. * is found.
  42. * @param {string} selector
  43. * @param {boolean} [err=true]
  44. * @returns {Element}
  45. */
  46. function $(selector, err) {
  47. if (err === undefined) {
  48. err = true;
  49. }
  50.  
  51. const element = document.querySelector(selector);
  52. if (err && element === null) {
  53. error('Element "' + selector + '" not found.');
  54. }
  55.  
  56. return element;
  57. }
  58.  
  59. /**
  60. * Event handler for when the verify age button is clicked.
  61. */
  62. function onBtnVerifyAgeClick() {
  63. setTimeout(onErrorVisibilityTimeout, ERROR_VISIBILITY_TIMEOUT);
  64. }
  65.  
  66. /**
  67. * Event handler for the error visibility timeout.
  68. */
  69. function onErrorVisibilityTimeout() {
  70. if (!$('.error-message.u-hide', false)) {
  71. // Error message is visible.
  72. return;
  73. }
  74.  
  75. const dobDay = $('#dobDay').value;
  76. const dobMonth = $('#dobMonth').value;
  77. const dobYear = $('#dobYear').value;
  78. localStorage.setItem(STORAGE_ITEM_KEY, `${dobDay}-${dobMonth}-${dobYear}`);
  79. }
  80.  
  81. /**
  82. * Main procedure.
  83. */
  84. function main() {
  85. const dob = localStorage.getItem(STORAGE_ITEM_KEY);
  86. if (typeof dob === 'string') {
  87. // Item exists.
  88. let dobSplit = dob.split('-');
  89. if (dobSplit.length !== 3) {
  90. error('Invalid date format.');
  91. }
  92.  
  93. $('#dobDay').value = dobSplit[0];
  94. $('#dobMonth').value = dobSplit[1];
  95. $('#dobYear').value = dobSplit[1];
  96. $('#btnVerifyAge').click();
  97. }
  98. else {
  99. // Item doesn't exist.
  100. $('#btnVerifyAge').addEventListener('click', onBtnVerifyAgeClick);
  101. }
  102. }
  103.  
  104. main();
  105. })();