Greasy Fork is available in English.

Lastest Doc Redirector (python, django, ruby)

Redirect the version you googled to the latest doc versions.

  1. // ==UserScript==
  2. // @name Lastest Doc Redirector (python, django, ruby)
  3. // @name:vi Chuyển trang tài liệu mới nhất (python, django, ruby)
  4. // @namespace https://github.com/hotmit/latest-doc-redirector-userscript
  5. // @version 1.0.1
  6. // @description Redirect the version you googled to the latest doc versions.
  7. // @description:vi Chuyển những trang bạn tìm được qua trang tài liệu với phiên bản mới nhất (python, django, ruby)
  8. // @author Du Dang
  9. // @include https://docs.djangoproject.com/*
  10. // @include https://docs.python.org/2/*
  11. // @include https://ruby-doc.org/core-*
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @license MIT
  15. // ==/UserScript==
  16. (function() {
  17. 'use strict';
  18.  
  19. // Change desired version number
  20. var PYTHON_TARGET_VERSION = '3.6';
  21. var DJANGO_TARGET_VERSION = '1.11';
  22. var RUBY_TARGET_VERSION = '2.4.1';
  23.  
  24. // region [ Str Lib ]
  25. var Str = {};
  26.  
  27. Str.contains = function(s, needle, caseSensitive) {
  28. if (caseSensitive){
  29. return s.indexOf(needle) > -1;
  30. }
  31. return s.toLowerCase().indexOf(needle.toLowerCase()) > -1;
  32. };
  33. // endregion
  34.  
  35. var href = window.location.href;
  36.  
  37. function forward(url){
  38. var lastFwd = GM_getValue('LastUrlFwd', '');
  39. // do this to allow browser to go back to old version
  40. // without loop redirect
  41. if (lastFwd != url){
  42. GM_setValue('LastUrlFwd', url);
  43. window.location.href = url;
  44. }
  45. }
  46.  
  47. if (Str.contains(href, 'docs.djangoproject.com') &&
  48. !Str.contains(href, '/en/' + DJANGO_TARGET_VERSION + '/'))
  49. {
  50. // https://docs.djangoproject.com/en/1.5/topics/db/optimization/
  51. // INTO https://docs.djangoproject.com/en/1.7/topics/db/optimization/
  52. href = href.replace(/docs.djangoproject.com\/(\w{2})\/(\d+\.\d+|dev)/gi,
  53. 'docs.djangoproject.com/en/' + DJANGO_TARGET_VERSION);
  54. forward(href);
  55. }
  56.  
  57. else if (Str.contains(href, 'docs.python.org') &&
  58. !Str.contains(href, '/' + PYTHON_TARGET_VERSION + '/'))
  59. {
  60. // https://docs.python.org/2/library/datetime.html
  61. // INTO https://docs.python.org/3/library/datetime.html
  62. href = href.replace(/docs.python.org\/2\/library/gi,
  63. 'docs.python.org/' + PYTHON_TARGET_VERSION + '/library');
  64. forward(href);
  65. }
  66.  
  67. else if (Str.contains(href, 'ruby-doc.org/core-') &&
  68. !Str.contains(href, '/core-' + RUBY_TARGET_VERSION + '/'))
  69. {
  70. // https://ruby-doc.org/core-2.2.0/String.html
  71. // INTO https://ruby-doc.org/core-2.3.1/String.html
  72. href = href.replace(/core-[^\/]+/gi, 'core-' + RUBY_TARGET_VERSION);
  73. forward(href);
  74. }
  75. })();