Jump New Laravel Document

Go to the latest version of the documentation page

  1. // ==UserScript==
  2. // @name Jump New Laravel Document
  3. // @description Go to the latest version of the documentation page
  4. // @namespace https://github.com/nathurru
  5. // @version 8.1
  6. // @author nathurru
  7. // @match https://readouble.com/laravel/*
  8. // @match https://laravel.com/*
  9. // @match https://lumen.laravel.com/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. let targetVersion = '8.x';
  17.  
  18. let referrerUrl = document.referrer;
  19. let locationUrl = location.href;
  20.  
  21. let versionReg = new RegExp(/(\d+\.[\dx]+)/);
  22. let referrerReg = new RegExp(/(laravel.com)|(readouble.com)/);
  23.  
  24. if (!referrerReg.test(referrerUrl)) {
  25. let ret = (versionReg.exec(locationUrl));
  26. if(ret !== null){
  27. let currentVersion = ret[1];
  28. if (targetVersion !== currentVersion) {
  29. location.href = locationUrl.replace(versionReg, targetVersion);
  30. }
  31. }
  32. }
  33. })();