nti56 qrcode dev hook token

二维码项目token放入localstorage便于复制

  1. // ==UserScript==
  2. // @name nti56 qrcode dev hook token
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description 二维码项目token放入localstorage便于复制
  6. // @author niushuai233
  7. // @match http://139.159.194.101/engineering/**
  8. // @icon http://139.159.194.101:21401/engineering/favicon.ico
  9. // @require https://unpkg.com/ajax-hook@2.0.3/dist/ajaxhook.min.js
  10. // @license GPL-3.0-only
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. Date.prototype.format = function(fmt) {
  17. var o = {
  18. "M+" : this.getMonth()+1, //月份
  19. "d+" : this.getDate(), //日
  20. "h+" : this.getHours(), //小时
  21. "m+" : this.getMinutes(), //分
  22. "s+" : this.getSeconds(), //秒
  23. "q+" : Math.floor((this.getMonth()+3)/3), //季度
  24. "S" : this.getMilliseconds() //毫秒
  25. };
  26. if(/(y+)/.test(fmt)) {
  27. fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  28. }
  29. for(var k in o) {
  30. if(new RegExp("("+ k +")").test(fmt)){
  31. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  32. }
  33. }
  34. return fmt;
  35. }
  36.  
  37. ah.proxy({
  38. //请求发起前进入
  39. onRequest: (config, handler) => {
  40. // console.log(config.headers);
  41. var token = config.headers.authorization;
  42.  
  43. if (token && token.length > 0) {
  44. window.localStorage.setItem('@qr token full', token);
  45. window.localStorage.setItem('@qr token', token.replace("Bearer ", ""));
  46. window.localStorage.setItem('@qr token reset time', new Date().format("yyyy-MM-dd hh:mm:ss"));
  47. }
  48. //var url_arr = config.url.split("?")
  49. //console.log(url_arr, new Date().toLocaleString())
  50. handler.next(config);
  51. },
  52. onError: (err, handler) => {
  53. console.log(err.type)
  54. handler.next(err)
  55. },
  56. //请求成功后进入
  57. onResponse: (response, handler) => {
  58. var res = response.response;
  59. //console.log(response)
  60. handler.next(response)
  61. }
  62. });
  63. })();