AcfunAvatarFix

修复顶端右侧小头像

目前为 2016-09-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name AcfunAvatarFix
  3. // @namespace zhihaofans
  4. // @version 0.1.1
  5. // @description 修复顶端右侧小头像
  6. // @author zhihaofans
  7. // @match http://www.acfun.tv/*
  8. // @match http://www.aixifan.com/*
  9. // @grant none
  10. // ==/UserScript==
  11. function setCookie(name, value) {
  12. var expdate = new Date();
  13. expdate.setTime(expdate.getTime() + 30 * 60 * 1000);
  14. document.cookie = name + "=" + value + ";expires=" + expdate.toGMTString() + ";path=/";
  15. }
  16. function getCookie(c_name) {
  17. if (document.cookie.length > 0) {
  18. c_start = document.cookie.indexOf(c_name + '=');
  19. if (c_start != -1) {
  20. c_start = c_start + c_name.length + 1;
  21. c_end = document.cookie.indexOf(';', c_start);
  22. if (c_end == -1) {
  23. c_end = document.cookie.length;
  24. }
  25. return decodeURI(document.cookie.substring(c_start, c_end));
  26. }
  27. }
  28. return '';
  29. }
  30. function acNotice(_mode, _text) {
  31. var patt1 = new RegExp('(/v/ac|/a/ac|/v/ab|/member/|/a/aa)');
  32. if (patt1.test(location.pathname, 'i')) {
  33. $.info(_mode, "AcfunAvatarFix:" + _text);
  34. } else {
  35. alert("AcfunAvatarFix\n" + _text);
  36. }
  37. }
  38. $(document).ready(function() {
  39. console.log("AcfunAvatarFix:开始载入");
  40. if (getCookie('auth_key') !== "") {
  41. if (getCookie('ac_userimg') === "") {
  42. $.get("/usercard.aspx?username=" + getCookie('ac_username'),
  43. function(data, status) {
  44. console.log("AcfunAvatarFix(status:" + status + ")");
  45. if (status == "success") {
  46. if (data.success === true) {
  47. setCookie("ac_userimg", data.userjson.avatar);
  48. if (getCookie('ac_userimg') == data.userjson.avatar) {
  49. console.log("AcfunAvatarFix:头像修复成功,刷新后生效");
  50. acNotice("success", "头像修复成功,刷新生效");
  51. } else {
  52. console.log("AcfunAvatarFix:获取个人信息失败(cookies)");
  53. acNotice("error", "保存cookies失败");
  54. }
  55. } else {
  56. console.log("AcfunAvatarFix:获取个人信息失败(api)");
  57. acNotice("error", "获取个人信息失败");
  58. }
  59. } else {
  60. console.log("AcfunAvatarFix:获取个人信息失败(网络)");
  61. acNotice("error", "获取个人信息失败,请检查网络");
  62. }
  63. });
  64. }
  65. }
  66. });