saved_resource(1) 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. !function(t,n,e){var a=!0,r={isVisible:function(t){var n=t.getBoundingClientRect(),e=n.width||n.right||0-n.left||0,a=n.height||n.bottom||0-n.top||0;return e>0&&a>0},isInSight:function(e){const a=e.parentNode,r=this.getDataset(a).pid,i=this.getDataset(e).src;if(-1!=n.cookie.indexOf("c_adb=")&&-1===i.indexOf("adBottom"))return!1;const c=t.innerWidth,s=["476","479","480"];if(c<1720&&-1!=s.indexOf(r))return!1;if("indexSuperise_"+r in localStorage)return!1;var o=e.getBoundingClientRect();if(this.isVisible(e)){var d=t.innerHeight;return o.top<=d+100}return!1},loadImg:function(t){var n=this;if(!t.src){var e=n.getDataset(t).src;t.src=e}},getDataset:function(t){if(t.dataset)return t.dataset;var n=t.attributes,e={};name,matchStr;for(var a=0;a<n.length;a++)matchStr=n[a].name.match(/^data-(.+)/),matchStr=n[a].name.match(/^data-(.+)/),matchStr&&(name=matchStr[1].replace(/-([\da-z])/gi,function(t,n){return n.toUpperCase()}),e[name]=n[a].value);return e},throttle:function(t){var n=null;return function(){var e=new Date,a=this,r=arguments;n||(n=e),e-n>=500&&(t.apply(a,r),n=e)}},checkImgs:function(){for(var t=this,n=e(".pre-img-lasy"),r=0;r<n.length;r++)t.isInSight(n[r])&&t.loadImg(n[r]);a=!0}};void 0===t.csdn&&(t.csdn={}),t.csdn.trackad=r,e(function(){csdn.trackad.checkImgs(),e(t).on("scroll",function(){a&&(a=!1,csdn.trackad.throttle(csdn.trackad.checkImgs()))}),e(t).on("resize",function(){e(this).width(),e(this).height();a&&(a=!1,csdn.trackad.throttle(csdn.trackad.checkImgs()))})})}(window,document,jQuery);;(function(window) {
  2. var svgSprite = '<svg><symbol id="sousuo" viewBox="0 0 1024 1024"><path d="M719.6779726 653.55865555l0.71080936 0.70145709 191.77828505 191.77828506c18.25658185 18.25658185 18.25658185 47.86273439 0 66.12399318-18.26593493 18.26125798-47.87208744 18.26125798-66.13334544 0l-191.77828505-191.77828506c-0.2338193-0.2338193-0.4676378-0.4676378-0.69678097-0.71081014-58.13206223 44.25257003-130.69075187 70.51978897-209.38952657 70.51978894C253.06424184 790.19776156 98.14049639 635.27869225 98.14049639 444.17380511S253.06424184 98.14049639 444.16912898 98.14049639c191.10488633 0 346.02863258 154.92374545 346.02863259 346.02863259 0 78.6987747-26.27189505 151.25746514-70.51978897 209.38952657z m-275.50884362 43.11621045c139.45428506 0 252.50573702-113.05145197 252.50573702-252.50573702s-113.05145197-252.50573702-252.50573702-252.50573783-252.50573702 113.05145197-252.50573783 252.50573783 113.05145197 252.50573702 252.50573783 252.50573702z" ></path></symbol><symbol id="gonggong_csdnlogo_" viewBox="0 0 4096 1024"><path d="M1234.16069807 690.46341551c62.96962316 23.02318413 194.30703694 45.91141406 300.51598128 45.91141406 114.44114969 0 178.13952547-31.68724287 183.2407937-80.86454822 4.642424-44.8587714-42.21366937-50.93170978-171.44579784-81.53931916-178.57137886-43.77913792-292.49970264-111.55313011-281.32549604-219.86735976 12.9825927-125.75031047 181.27046257-220.78504823 439.49180199-220.78504822 125.88526465 0 247.93783044 8.87998544 311.17736197 29.60894839l-21.7006331 158.57116851c-41.05306337-14.27815288-198.1937175-34.11641822-304.48363435-34.11641822-107.7744129 0-163.56447339 33.90049151-167.42416309 71.06687432-4.85835069 47.04502922 51.14763648 49.23128703 191.14910897 86.50563321 189.58364043 48.09767188 272.47250144 115.81768239 261.6221849 220.81203906-12.71268432 123.51007099-164.13128096 228.53141851-466.48263918 228.53141851-125.85827383 0-234.33444849-22.96920244-294.09216204-45.93840492l19.730302-157.86940672zM3010.8325562 172.75216735c688.40130256-129.79893606 747.80813523 103.42888812 726.53935551 309.80082928l-40.08139323 381.78539207h-218.51781789l36.57258439-348.20879061c7.90831529-76.68096846 57.13960232-226.66905073-180.54170997-221.05495659-82.26807176 1.99732195-123.05122675 13.2794919-123.05122677 13.27949188s-7.15257186 92.65954408-15.81663059 161.13529804l-41.43093509 394.84895728h-214.3072473l42.53755943-389.15389062 28.09746151-302.43233073z m-869.48282929-18.05687008c49.12332368-5.34418577 124.58970448-10.76934404 228.45044598-10.76934405 173.38913812 0 313.57954648 30.17575597 400.38207891 93.63121421 77.94953781 59.16391512 129.82592689 154.95439631 115.4668015 293.74128117-13.25250106 129.15115596-80.405704 219.57046055-178.16651631 275.4954752-89.44763445 52.74009587-202.16137055 75.27744492-371.66382812 75.27744493-99.94707012 0-195.27870708-5.39816743-267.77609576-16.14052064L2141.37671774 154.69529727z m143.26736381 569.85754561c16.70732823 3.23890047 38.67786969 6.45081009 81.99816339 6.45081009 173.44311979 0 295.7386031-85.23706385 308.01943403-205.07638097 17.84094339-173.2271931-90.63523129-233.79463176-273.39018992-232.74198912-23.67096422 0-56.57279475 0-73.98188473 3.1849188l-42.6725136 428.15565036z" fill="#262626" ></path><path d="M1109.8678928 870.30336371c-41.10704503 14.25116203-126.26313639 23.96786342-245.23874671 23.96786342-342.13585224 0-526.8071603-160.59548129-504.97157302-372.90540663C385.78470347 268.40769434 659.36382925 126.08500985 958.9081404 126.08500985c116.00661824 0 184.32042718 9.33882968 248.31570215 24.99351522l-20.5400271 170.42014604c-42.56455024-14.33213455-142.32268451-27.50366309-223.07926938-27.50366311-176.25016686 0-325.94134993 52.49717834-343.10752238 218.57179958-15.30380469 148.50358623 89.7715245 219.48948804 288.04621451 219.48948804 69.0155707 0 170.77102691-9.8786464 217.81605614-24.15679928l-16.49140154 162.40386737z" fill="#CA0C16" ></path></symbol><symbol id="gonggong_csdnlogodanse_" viewBox="0 0 4096 1024"><path d="M1229.41995733 690.46341551c62.96962316 23.02318413 194.30703694 45.91141406 300.51598128 45.91141406 114.44114969 0 178.13952547-31.68724287 183.2407937-80.86454822 4.642424-44.8587714-42.21366937-50.93170978-171.44579784-81.53931916-178.57137886-43.77913792-292.49970264-111.55313011-281.32549604-219.86735976 12.9825927-125.75031047 181.27046257-220.78504823 439.49180199-220.78504822 125.88526465 0 247.93783044 8.87998544 311.17736197 29.60894839l-21.7006331 158.57116851c-41.05306337-14.27815288-198.1937175-34.11641822-304.48363435-34.11641822-107.7744129 0-163.56447339 33.90049151-167.42416309 71.06687432-4.85835069 47.04502922 51.14763648 49.23128703 191.14910897 86.50563321 189.58364043 48.09767188 272.47250144 115.81768239 261.6221849 220.81203906-12.71268432 123.51007099-164.13128096 228.53141851-466.48263918 228.53141851-125.85827383 0-234.33444849-22.96920244-294.09216204-45.93840492l19.730302-157.86940672zM3006.09181546 172.75216735c688.40130256-129.79893606 747.80813523 103.42888812 726.53935551 309.80082928l-40.08139323 381.78539207h-218.51781789l36.57258439-348.20879061c7.90831529-76.68096846 57.13960232-226.66905073-180.54170997-221.05495659-82.26807176 1.99732195-123.05122675 13.2794919-123.05122677 13.27949188s-7.15257186 92.65954408-15.81663059 161.13529804l-41.43093509 394.84895728h-214.3072473l42.53755943-389.15389062 28.09746151-302.43233073z m-869.48282929-18.05687008c49.12332368-5.34418577 124.58970448-10.76934404 228.45044598-10.76934405 173.38913812 0 313.57954648 30.17575597 400.38207891 93.63121421 77.94953781 59.16391512 129.82592689 154.95439631 115.4668015 293.74128117-13.25250106 129.15115596-80.405704 219.57046055-178.16651631 275.4954752-89.44763445 52.74009587-202.16137055 75.27744492-371.66382812 75.27744493-99.94707012 0-195.27870708-5.39816743-267.77609576-16.14052064L2136.635977 154.69529727z m143.26736381 569.85754561c16.70732823 3.23890047 38.67786969 6.45081009 81.99816339 6.45081009 173.44311979 0 295.7386031-85.23706385 308.01943403-205.07638097 17.84094339-173.2271931-90.63523129-233.79463176-273.39018992-232.74198912-23.67096422 0-56.57279475 0-73.98188473 3.1849188l-42.6725136 428.15565036z m-1174.74919792 145.75052083c-41.10704503 14.25116203-126.26313639 23.96786342-245.23874671 23.96786342-342.13585224 0-526.8071603-160.59548129-504.97157303-372.90540663C381.04396273 268.40769434 654.62308851 126.08500985 954.16739966 126.08500985c116.00661824 0 184.32042718 9.33882968 248.31570215 24.99351522l-20.5400271 170.42014604c-42.56455024-14.33213455-142.32268451-27.50366309-223.07926938-27.50366311-176.25016686 0-325.94134993 52.49717834-343.10752238 218.57179958-15.30380469 148.50358623 89.7715245 219.48948804 288.04621451 219.48948804 69.0155707 0 170.77102691-9.8786464 217.81605614-24.15679928l-16.49140154 162.40386737z" ></path></symbol><symbol id="xieboke1" viewBox="0 0 1024 1024"><path d="M204.70021457 751.89799169h657.99199211a33.6932867 33.6932867 0 0 1 0 67.33536736H163.68452703a33.53966977 33.53966977 0 0 1-18.74125054-5.68382181c-18.63883902-9.4218307-18.17798882-29.44322156-15.20806401-39.17228615C199.0675982 570.27171976 309.41567149 409.58853908 435.38145354 290.12586836A243.22661203 243.22661203 0 0 1 536.97336934 234.20935065c138.10150976-33.79569759 228.3257813-29.95527721 318.60125827-28.52152054-17.15387692 20.48224105-36.20236071 41.6301547-57.29906892 62.93168529-3.1747472 3.22595323-164.67721739 19.91897936-187.97576692 47.05794871-23.29854894 27.13896932 129.60138005 7.37360691 125.19769798 11.11161576-21.6599699 18.33160576-44.90731339 36.4071831-69.94685287 53.8682939-4.50609297 3.1747472-149.52035944-0.35843931-174.61110436 27.85584737-25.19315641 28.16308124 101.89914903 18.12678338 96.0617103 21.40394206-67.43777825 37.63611797-125.96578207 64.62147036-212.70807253 93.8086635-57.65750823 19.4069231-121.8181284 133.13456658-146.5504346 179.06599187a435.75967738 435.75967738 0 0 0-23.04252112 49.10617311z" fill="#CA0C16" ></path></symbol><symbol id="gitchat" viewBox="0 0 1024 1024"><path d="M892.08971773 729.08552746h-108.597062v-162.89559374H403.40293801v-108.59706198h488.68677972v271.49265572z m-651.58237345 54.298531V783.49265572h488.68678045v108.59706201H131.91028227V131.91028227h760.17943546v217.19412473h-108.597062V240.50734428H240.50734428v542.87671418z m542.98531145 0h108.597062v108.59706199h-108.597062v-108.59706199z" fill="#FF9100" ></path></symbol><symbol id="toolbar-memberhead" viewBox="0 0 1303 1024"><path d="M1061.51168438 433.79527648A78.51879902 78.51879902 0 1 1 1129.35192643 472.74060007h-1.80593246l-48.05350474 403.97922198c-4.55409058 38.16013652-39.41643684 67.133573-80.79584389 67.13357302H319.35199503c-41.30088817 0-76.00619753-28.81639958-80.717325-66.97653526L189.01078861 472.74060007H187.12633728a78.51879902 78.51879902 0 1 1 67.76172401-38.86680556l193.31328323 119.81968805 158.13686148-336.06046024A78.5973179 78.5973179 0 0 1 658.23913228 80.14660493a78.51879902 78.51879902 0 0 1 51.58685077 137.721974l158.13686147 335.82490362 193.54883986-119.89820607z" fill="#FDD840" ></path><path d="M1050.8331274 394.22180104a78.51879902 78.51879902 0 1 1 78.51879903 78.51879903h-1.80593246l-48.05350474 403.97922198c-4.55409058 38.16013652-39.41643684 67.133573-80.79584389 67.13357302H659.02432018C658.47468805 793.25433807 658.23913228 505.32590231 658.23913228 80.14660493a78.51879902 78.51879902 0 0 1 51.58685077 137.721974l158.13686147 335.82490362 193.54883986-119.89820607A78.51879902 78.51879902 0 0 1 1050.8331274 394.22180104z" fill="#FFBE00" ></path></symbol><symbol id="toolbar-m-memberhead" viewBox="0 0 1303 1024"><path d="M1062.74839935 433.79527648A78.51879902 78.51879902 0 1 1 1130.58864141 472.74060007h-1.80593246l-48.05350474 403.97922198c-4.55409058 38.16013652-39.41643685 67.133573-80.79584389 67.13357302H320.58871c-41.30088817 0-76.00619753-28.81639958-80.71732499-66.97653526L190.24750358 472.74060007H188.36305226a78.51879902 78.51879902 0 1 1 67.761724-38.86680556l193.31328324 119.81968805 158.13686147-336.06046024A78.5973179 78.5973179 0 0 1 659.47584726 80.14660493a78.51879902 78.51879902 0 0 1 51.58685076 137.721974l158.13686148 335.82490362 193.54883985-119.89820607z" fill="#D6D6D6" ></path><path d="M1052.06984238 394.22180104a78.51879902 78.51879902 0 1 1 78.51879903 78.51879903h-1.80593246l-48.05350474 403.97922198c-4.55409058 38.16013652-39.41643685 67.133573-80.79584389 67.13357302H660.26103515C659.71140302 793.25433807 659.47584726 505.32590231 659.47584726 80.14660493a78.51879902 78.51879902 0 0 1 51.58685076 137.721974l158.13686148 335.82490362 193.54883985-119.89820607A78.51879902 78.51879902 0 0 1 1052.06984238 394.22180104z" fill="#C1C1C1" ></path></symbol><symbol id="csdnc-upload" viewBox="0 0 1024 1024"><path d="M216.37466416 723.16095396v84.46438188h591.25067168v-84.46438188c0-23.32483876 18.90735218-42.23219094 42.23219093-42.23219021s42.23219094 18.90735218 42.23219096 42.23219021v84.46438188c0 46.64967827-37.81470362 84.46438188-84.46438189 84.46438189H216.37466416c-46.64967827 0-84.46438188-37.81470362-84.46438189-84.4643819v-84.46438187c0-23.32483876 18.90735218-42.23219094 42.23219096-42.23219021s42.23219094 18.90735218 42.23219094 42.23219021zM469.76780906 275.55040991L246.55378774 499.53305726a42.30820888 42.30820888 0 0 1-59.99082735 0c-16.56346508-16.62259056-16.56346508-43.57095155 0-60.19354139L480.51167818 144.38144832A42.21952103 42.21952103 0 0 1 512 131.93984464a42.20262858 42.20262858 0 0 1 31.48409853 12.44160369l293.95294108 294.95806754c16.56346508 16.62259056 16.56346508 43.57095155 0 60.19354139a42.30820888 42.30820888 0 0 1-59.99082735 0L554.23219094 275.55040991V680.92876375c0 23.32483876-18.90735218 42.23219094-42.23219094 42.23219021s-42.23219094-18.90735218-42.23219094-42.23219021V275.55040991z" ></path></symbol></svg>';
  3. var script = function() {
  4. var scripts = document.getElementsByTagName("script");
  5. return scripts[scripts.length - 1]
  6. } ();
  7. var shouldInjectCss = script.getAttribute("data-injectcss");
  8. var ready = function(fn) {
  9. if (document.addEventListener) {
  10. if (~ ["complete", "loaded", "interactive"].indexOf(document.readyState)) {
  11. setTimeout(fn, 0)
  12. } else {
  13. var loadFn = function() {
  14. document.removeEventListener("DOMContentLoaded", loadFn, false);
  15. fn()
  16. };
  17. document.addEventListener("DOMContentLoaded", loadFn, false)
  18. }
  19. } else if (document.attachEvent) {
  20. IEContentLoaded(window, fn)
  21. }
  22. function IEContentLoaded(w, fn) {
  23. var d = w.document,
  24. done = false,
  25. init = function() {
  26. if (!done) {
  27. done = true;
  28. fn()
  29. }
  30. };
  31. var polling = function() {
  32. try {
  33. d.documentElement.doScroll("left")
  34. } catch(e) {
  35. setTimeout(polling, 50);
  36. return
  37. }
  38. init()
  39. };
  40. polling();
  41. d.onreadystatechange = function() {
  42. if (d.readyState == "complete") {
  43. d.onreadystatechange = null;
  44. init()
  45. }
  46. }
  47. }
  48. };
  49. var prepend = function(el, target) {
  50. target.appendChild(el)
  51. };
  52. function appendSvg() {
  53. var div, svg;
  54. div = document.createElement("div");
  55. div.innerHTML = svgSprite;
  56. svgSprite = null;
  57. svg = div.getElementsByTagName("svg")[0];
  58. if (svg) {
  59. svg.setAttribute("aria-hidden", "true");
  60. svg.style.position = "absolute";
  61. svg.style.width = 0;
  62. svg.style.height = 0;
  63. svg.style.overflow = "hidden";
  64. prepend(svg, document.body)
  65. }
  66. }
  67. if (shouldInjectCss && !window.__iconfont__svg__cssinject__) {
  68. window.__iconfont__svg__cssinject__ = true;
  69. try {
  70. document.write("<style>.svgfont {display: inline-block;width: 1em;height: 1em;fill: currentColor;vertical-align: -0.1em;font-size:16px;}</style>")
  71. } catch(e) {
  72. console && console.log(e)
  73. }
  74. }
  75. ready(appendSvg)
  76. })(window);(function(window){
  77. /**
  78. * @brief Notifier
  79. *
  80. * @param type 1. 一直提示 2,更新提示内容 3, 控制显示上限。超过个数删除最早的 4,超时更新
  81. * @param param 本参数在type为3,4时才有效, type为3表示可以最多显示通知的个数 4, 表示多少秒后删除了
  82. *
  83. * @return
  84. */
  85. function Notifier() {};
  86. window.Notifier = Notifier;
  87. type = 1;
  88. queue = [];
  89. t = 5;
  90. c = 3;
  91. _notifier = undefined ;
  92. if(undefined !== window.webkitNotifications) {
  93. _notifier = window.webkitNotifications;
  94. }else if (undefined !== window.Notification) {
  95. _notifier = window.Notification;
  96. } else {
  97. // console.log('error not found notification!')
  98. }
  99. window.Notifier.ModelAll = function() {
  100. type = 1;
  101. }
  102. window.Notifier.ModelUpdate = function() {
  103. type = 2;
  104. }
  105. window.Notifier.ModelCount = function(ct) {
  106. if(ct !== undefined) c = ct;
  107. type = 3;
  108. }
  109. window.Notifier.ModelTimeout = function(timeout) {
  110. if(timeout !== undefined) t = timeout;
  111. type = 4;
  112. }
  113. window.Notifier.HasSupport = function() {
  114. if(undefined === _notifier) {
  115. return false;
  116. }
  117. return true;
  118. }
  119. window.Notifier.GetPermission = function() {
  120. return _notifier.checkPermission();
  121. }
  122. window.Notifier.IsGetPermission = function() {
  123. return (_notifier === 0);
  124. }
  125. window.Notifier.Disable = function() {
  126. return (_notifier.checkPermission === 2);
  127. }
  128. window.Notifier.RequestPermission = function(cb) {
  129. _notifier.requestPermission(function() {
  130. if(cb) {cb(_notifier.checkPermission() == 0)}
  131. });
  132. }
  133. //type = 1;关闭上一个
  134. window.Notifier.Close = function(type) {
  135. if(type = 1) {
  136. tmp = queue.pop();
  137. } else {
  138. tmp = queue.shift();
  139. }
  140. _closeItem(tmp);
  141. }
  142. window.Notifier.ClosePre = function () {
  143. tmp = queue.pop();
  144. _closeItem(tmp);
  145. }
  146. window.Notifier.CloseLast = function () {
  147. tmp = queue.shift();
  148. _closeItem(tmp);
  149. }
  150. window.Notifier.CloseAll = function() {
  151. while(queue.length > 0) {
  152. var tmp = queue.shift();
  153. _closeItem(tmp);
  154. }
  155. }
  156. window.Notifier.Notify = function(icon, title, body) {
  157. if (this.IsGetPermission() == 0) {
  158. var popup = _createNotificationAndShow(icon, title, body);
  159. if(undefined == popup) {
  160. return false;
  161. }
  162. switch(type) {
  163. case 2:
  164. if(queue.length > 0) {
  165. tmp = queue.pop();
  166. _closeItem(tmp);
  167. }
  168. break;
  169. case 3:
  170. while(queue.length >= c) {
  171. tmp = queue.shift();
  172. _closeItem(tmp);
  173. }
  174. break;
  175. case 4:
  176. setTimeout(function(){_closeItem(popup);}, t*1000);
  177. break;
  178. }
  179. var q = queue;
  180. popup.onclose = function(){
  181. var cur = q.indexOf(popup);
  182. if(cur >= 0) {
  183. q.splice(cur, 1);
  184. }
  185. };
  186. popup.onclick = function(){};
  187. queue.push(popup);
  188. return true;
  189. } else {
  190. RequestPermission();
  191. }
  192. return false;
  193. }
  194. function _createNotificationAndShow(icon, title, body) {
  195. if(undefined != window.webkitNotifications && _notifier.name === window.webkitNotifications.name) {
  196. var n = _notifier.createNotification(icon, title, body);
  197. n.show();
  198. return n;
  199. }else if (undefined !== window.Notification && _notifier.name === window.Notification.name) {
  200. return new _notifier(title, {icon:icon, body: body});
  201. } else {
  202. // console.log('error not found notification!')
  203. // alert(title +"\n\n"+body);
  204. return undefined;
  205. }
  206. }
  207. function _closeItem(n) {
  208. if(undefined == n) {
  209. return
  210. }
  211. if(n.cancel) {
  212. n.cancel();
  213. } else {
  214. n.close();
  215. }
  216. }
  217. })(window);
  218. 'use strict';
  219. (function(){
  220. const applicationServerPublicKey = 'BCYaMwiS92AJlv9Eg2YXSFwuI3ppbydkz31gOI5NS7YtOp05n7qUHEyb_iijzQcjgWqrsGSj2K18F21G9DYL4-U';
  221. let isSubscribed = false;
  222. let swRegistration = null;
  223. var linkUrl = ''
  224. function getBrowserInfo() {
  225. var agent = navigator.userAgent.toLowerCase();
  226. var regStr_ie = /msie [\d.]+;/gi;
  227. var regStr_ff = /firefox\/[\d.]+/gi
  228. var regStr_chrome = /chrome\/[\d.]+/gi;
  229. var regStr_saf = /safari\/[\d.]+/gi;
  230. var isIE = agent.indexOf("compatible") > -1 && agent.indexOf("msie" > -1); //判断是否IE<11浏览器
  231. var isEdge = agent.indexOf("edge") > -1 && !isIE; //判断是否IE的Edge浏览器
  232. var isIE11 = agent.indexOf('trident') > -1 && agent.indexOf("rv:11.0") > -1;
  233. if (isIE) {
  234. var reIE = new RegExp("msie (\\d+\\.\\d+);");
  235. reIE.test(agent);
  236. var fIEVersion = parseFloat(RegExp["$1"]);
  237. if (fIEVersion == 7) {
  238. return "IE/7";
  239. } else if (fIEVersion == 8) {
  240. return "IE/8";
  241. } else if (fIEVersion == 9) {
  242. return "IE/9";
  243. } else if (fIEVersion == 10) {
  244. return "IE/10";
  245. }
  246. } //isIE end
  247. if (isIE11) {
  248. return "IE/11";
  249. }
  250. //firefox
  251. if (agent.indexOf("firefox") > 0) {
  252. return agent.match(regStr_ff);
  253. }
  254. //Safari
  255. if (agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0) {
  256. return agent.match(regStr_saf);
  257. }
  258. //Chrome
  259. if (agent.indexOf("chrome") > 0) {
  260. return agent.match(regStr_chrome);
  261. }
  262. }
  263. function urlB64ToUint8Array(base64String) {
  264. const padding = '='.repeat((4 - base64String.length % 4) % 4);
  265. const base64 = (base64String + padding)
  266. .replace(/\-/g, '+')
  267. .replace(/_/g, '/');
  268. const rawData = window.atob(base64);
  269. const outputArray = new Uint8Array(rawData.length);
  270. for (let i = 0; i < rawData.length; ++i) {
  271. outputArray[i] = rawData.charCodeAt(i);
  272. }
  273. return outputArray;
  274. }
  275. if ('serviceWorker' in navigator && 'PushManager' in window) {
  276. var _hmt = window._hmt || [];
  277. var hasSub = getCookie('c_hasSub')
  278. // 判断域名的操作 如果域名是blog 和download
  279. var flagBox1 = window.location.host.indexOf('blog')>=0 ?'true':'false'
  280. var flagBox2 = window.location.host.indexOf('download')>=0 ?'true':'false'
  281. var fs = window.RequestFileSystem || window.webkitRequestFileSystem;
  282. if (!fs) {
  283. console.log("check failed");
  284. handleRight()
  285. } else {
  286. fs(window.TEMPORARY,100,function(){
  287. //console.log('非隐身模式');
  288. handleRight()
  289. },function(){
  290. //console.log('隐身模式');
  291. return false
  292. });
  293. }
  294. navigator.serviceWorker.addEventListener('message', function (event) {
  295. console.log('收到sw的消息event====',event)
  296. if (event.data === 'showBox') {
  297. _hmt.push(['_trackEvent', '推送消息弹框', '消息', '', '展示推送弹框'])
  298. }
  299. if (event.data === 'openLink') {
  300. _hmt.push(['_trackEvent', '打开消息链接', '消息', '', '打开消息链接'])
  301. }
  302. });
  303. } else {
  304. //火狐浏览器隐身模式下 serviceWorker属性都不支持 safari不支持 可以全站推送 走此逻辑
  305. var flagBox1 = window.location.host.indexOf('blog')>=0 ?'true':'false'
  306. var flagBox2 = window.location.host.indexOf('download')>=0 ?'true':'false'
  307. if(flagBox1 === 'true' || flagBox2 === 'true' ){
  308. if ('serviceWorker' in navigator) {
  309. // 注册service worker
  310. navigator.serviceWorker.register('/sw.js').then(function (registration) {
  311. return askPermission();
  312. }).then(function () {
  313. console.log('safari授权成功了====')
  314. var subscription = '-'
  315. handleAjax(subscription)
  316. // workOrderSync()
  317. })
  318. navigator.serviceWorker.addEventListener('message', function (event) {
  319. console.log('收到sw的消息event11====',event)
  320. if (event.data === 'showBox') {
  321. _hmt.push(['_trackEvent', '推送消息弹框', '消息', '', '展示推送弹框'])
  322. }
  323. if (event.data === 'openLink') {
  324. _hmt.push(['_trackEvent', '打开消息链接', '消息', '', '打开消息链接'])
  325. }
  326. });
  327. }
  328. }
  329. }
  330. //
  331. function askPermission() {
  332. return new Promise(function (resolve, reject) {
  333. var permissionResult = Notification.requestPermission(function (result) {
  334. resolve(result);
  335. });
  336. if (permissionResult) {
  337. permissionResult.then(resolve, reject);
  338. }
  339. }).then(function (permissionResult) {
  340. if (permissionResult !== 'granted') {
  341. throw new Error('We weren\'t granted permission.');
  342. }
  343. });
  344. }
  345. // 操作权限
  346. function handleRight() {
  347. if((hasSub!=='true'&&flagBox1 === 'true')||(hasSub!=='true'&&flagBox2 === 'true')){
  348. // 没有授权的操作
  349. // if((hasSub!=='true')||(hasSub!=='true')){
  350. var Notification = window.Notification || window.mozNotification || window.webkitNotification;
  351. navigator.serviceWorker.register('/sw.js')
  352. .then(function(swReg) {
  353. //console.log('注册成功了')
  354. swRegistration = swReg;
  355. workOrderSync(swRegistration)
  356. // sw注册后调用检查用户是否订阅通知的函数
  357. initialiseUI();
  358. Notification.requestPermission(function(status){
  359. if(status==='denied'&& getCookie('firstDie')!=='1'){
  360. // 隐身模式下不弹框 默认直接拒绝授权
  361. // && getCookie('firstDie')!=='1'
  362. //用户拒绝授权 再次选择 弹出授权框拒绝才能再次记录
  363. _hmt.push(['_trackEvent', '弹出框', '拒绝授权', '', 'rejectRightBox'])
  364. // console.log('执行rejectRightBox')
  365. setCookie('firstDie','1',1)
  366. } else if(status==='granted'){
  367. // 用户同意授权
  368. // 授权过的就不再进入这个里面了
  369. //执行了授权 只能清缓存 弹出授权框允许才能再次记录
  370. //debugger
  371. subscribeUser()
  372. }
  373. })
  374. })
  375. .catch(function(error) {
  376. //console.log('隐身模式下注册不成功')
  377. var browser = getBrowserInfo()[0] || '';
  378. //console.log('browser',browser)
  379. _hmt.push(['_trackEvent', 'serviceWorker', '报错', '', 'serviceWorker报错'])
  380. _hmt.push(['_trackEvent', '浏览器版本精确版本', browser, '', '真实不能注册的浏览器版本'])
  381. // $.get('https://statistic.csdn.net/notification/error?brower='+browser)
  382. });
  383. // 可以手动获取权限 但是否去选择弹出是不知道的
  384. // navigator.serviceWorker.ready.then(function(swRegistration) {
  385. // console.log('workOrderSync执行了')
  386. // return swRegistration.sync.register("workOrderSync");
  387. // });
  388. }else{
  389. navigator.serviceWorker.ready.then(function(swRegistration) {
  390. // //console.log('刷新走了else====进入了workSync')
  391. // return swRegistration.sync.register("workOrderSync");
  392. // var options = {
  393. // body: 'heihei',
  394. // icon: 'img/logo.png',
  395. // badge: 'img/badge.png'
  396. // };
  397. // var title = 'haha666';
  398. // swRegistration.showNotification(title, options);
  399. workOrderSync(swRegistration)
  400. });
  401. // 注册过的和不是blog 或者 download 域名下如果接口数据有返回 的可以直接拿数据展示
  402. }
  403. }
  404. function workOrderSync(swRegistration) {
  405. var opts = {
  406. method:"POST", //请求方法
  407. body:{}, //请求体
  408. headers: {
  409. 'Accept': 'application/json',
  410. 'Content-Type': 'application/json',
  411. },
  412. credentials: "include"
  413. }
  414. // setInterval(function () {
  415. // // https://test-notification.csdn.net/notifiction/fe/getbyusername
  416. // fetchData(opts,swRegistration)
  417. // }, 20000)
  418. // fetchData(opts,swRegistration)
  419. }
  420. function fetchData(opts,swRegistration){
  421. // 测试环境地址 https://test-notify.csdn.net/notifiction/fe/getbyusername
  422. fetch("https://msg.csdn.net/v1/chrome/notification/view",opts).then(res=> {
  423. return res.json()
  424. }).then(res=> {
  425. //console.log('res1===',res);
  426. var jsonData = res.data
  427. //console.log('jsonData===',jsonData);
  428. var title = jsonData.title;
  429. linkUrl = jsonData.url || ''
  430. var username= jsonData.username || ''
  431. var options = {
  432. body: jsonData.message,
  433. icon: 'img/logo.png',
  434. badge: 'img/badge.png',
  435. data:linkUrl
  436. // actions: [{
  437. // action: '',
  438. // title: ''
  439. // }]
  440. };
  441. var browser = getBrowserInfo()[0] || '';
  442. console.log('浏览器信息输出browser',browser)
  443. if(JSON.stringify(jsonData)!=='{}'&&res.status){
  444. if(browser&&browser.indexOf('safari/')>-1){
  445. var notification = new Notification(title, options);
  446. console.log('走了safari逻辑里面====',notification)
  447. notification.addEventListener('click', function (e) {
  448. window.location.href = linkUrl
  449. });
  450. } else {
  451. swRegistration.showNotification(title, options)
  452. }
  453. _hmt.push(['_trackEvent', '展示推送消息弹框', '消息', username ])
  454. }
  455. }).catch(err=> {
  456. //console.log(err);
  457. })
  458. }
  459. // 检查用户当前有没有订阅
  460. function initialiseUI() {
  461. swRegistration.pushManager.getSubscription()
  462. .then(function(subscription) {
  463. isSubscribed = !(subscription === null);
  464. if (isSubscribed) {
  465. } else {
  466. }
  467. updateBtn();
  468. });
  469. }
  470. // cookie
  471. function setCookie(cname, cvalue, exdays) {
  472. var d = new Date();
  473. d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  474. var expires = "expires=" + d.toUTCString();
  475. document.cookie = cname + "=" + cvalue + "; " + expires+";domain=csdn.net;path=/"
  476. // console.log(d)
  477. }
  478. //获取cookie
  479. function getCookie(cname) {
  480. var name = cname + "=";
  481. var ca = document.cookie.split(';');
  482. for(var i = 0; i < ca.length; i++) {
  483. var c = ca[i];
  484. while(c.charAt(0) == ' ') c = c.substring(1);
  485. if(c.indexOf(name) != -1) return c.substring(name.length, c.length);
  486. }
  487. return "";
  488. }
  489. function delCookie(name)
  490. {
  491. var exp = new Date();
  492. exp.setTime(exp.getTime() - 1);
  493. var cval=getCookie(name);
  494. if(cval!=null)
  495. document.cookie= name + "="+cval+";expires="+exp.toUTCString()+';domain=csdn.net;path=/';
  496. }
  497. //启用我们的按钮,以及更改用户是否订阅的文本
  498. function updateBtn() {
  499. // 只执行一次 如何监听
  500. if (Notification.permission === 'denied') {
  501. return;
  502. }
  503. if(Notification.permission === 'default'){
  504. _hmt.push(['_trackEvent', '弹出框', '展示授权弹框', '', 'showRightBox'])
  505. //console.log('执行showRightBox')
  506. delCookie('firstDie')
  507. delCookie('c_hasSub')
  508. }
  509. if(Notification.permission === 'granted'){
  510. }
  511. if (isSubscribed) {
  512. } else {
  513. }
  514. }
  515. function subscribeUser() {
  516. const applicationServerKey = urlB64ToUint8Array(applicationServerPublicKey);
  517. // 传递公钥给sw服务器
  518. //debugger
  519. swRegistration.pushManager.subscribe({
  520. userVisibleOnly: true,
  521. // 默认允许订阅后发送通知
  522. applicationServerKey: applicationServerKey
  523. })
  524. .then(function(subscription) {
  525. // setCookie('firstEnter','1',1)
  526. handleAjax(subscription)
  527. _hmt.push(['_trackEvent', '弹出框', '允许授权', '', 'agreeRightBox'])
  528. // console.log('执行agreeRightBox2')
  529. isSubscribed = true
  530. //updateBtn()
  531. })
  532. .catch(function(err) {
  533. // updateBtn()
  534. _hmt.push(['_trackEvent', '请求接口', '失败', '', '接口报错'])
  535. });
  536. }
  537. function handleAjax(subscription){
  538. var xhr;
  539. if (window.XMLHttpRequest)
  540. {
  541. // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
  542. xhr = new XMLHttpRequest();
  543. }
  544. else
  545. {
  546. // IE6, IE5 浏览器执行代码
  547. xhr = new ActiveXObject("Microsoft.XMLHTTP");
  548. }
  549. //设置请求的类型及url
  550. // application/x-www-form-urlencoded
  551. xhr.open('post', 'https://msg.csdn.net/chrome/v1/browse_info/save_browse_info' );
  552. //发送请求
  553. // https://msg.csdn.net/chrome/v1/browse_info/save_browse_info
  554. // 变更请求地址之前: https://gw.csdn.net/cui-service/v1/browse_info/save_browse_info
  555. //post请求一定要添加请求头才行不然会报错 open后send前
  556. xhr.setRequestHeader("Content-type","application/json");
  557. var jsonData = ''
  558. if(typeof(subscription) === 'string'){
  559. jsonData ={'subscription':subscription}
  560. } else {
  561. jsonData ={'subscription':JSON.stringify(subscription)}
  562. }
  563. xhr.withCredentials = true;
  564. xhr.send(JSON.stringify(jsonData));
  565. xhr.onreadystatechange = function () {
  566. // 这步为判断服务器是否正确响应
  567. if (xhr.readyState == 4 && xhr.status == 200) {
  568. //console.log(xhr.responseText);
  569. setCookie('c_hasSub',true,1)
  570. }
  571. };
  572. }
  573. }(window))