{"id":149454,"date":"2020-08-25T14:04:59","date_gmt":"2020-08-25T06:04:59","guid":{"rendered":"http:\/\/4563.org\/?p=149454"},"modified":"2020-08-25T14:04:59","modified_gmt":"2020-08-25T06:04:59","slug":"tampermonkey-%e5%a6%82%e4%bd%95%e8%87%aa%e5%8a%a8%e5%a1%ab%e5%85%85%e5%af%86%e7%a0%81-%e5%b9%b6%e9%80%9a%e8%bf%87%e5%89%8d%e7%ab%af%e7%9a%84%e8%a1%a8%e5%8d%95%e6%a3%80%e6%9f%a5","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=149454","title":{"rendered":"tampermonkey \u5982\u4f55\u81ea\u52a8\u586b\u5145\u5bc6\u7801 \u5e76\u901a\u8fc7\u524d\u7aef\u7684\u8868\u5355\u68c0\u67e5"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  tampermonkey \u5982\u4f55\u81ea\u52a8\u586b\u5145\u5bc6\u7801 \u5e76\u901a\u8fc7\u524d\u7aef\u7684\u8868\u5355\u68c0\u67e5               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : cy97cool <\/span>  <span><i><\/i> 8<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u9700\u6c42\uff1a\u7c7b\u4f3c LastPass \u8fd9\u79cd\u53ef\u4ee5\u81ea\u52a8\u586b\u5145\u7528\u6237\u540d\u5bc6\u7801\uff0c\u70b9\u51fb\u63d0\u4ea4<\/p>\n<p>\u96be\u70b9\uff1a\u5f88\u591a\u73b0\u4ee3\u5316\u7684\u9875\u9762\u524d\u7aef\u505a\u4e86\u8868\u5355\u6821\u9a8c\uff0c\u76f4\u63a5\u8d4b\u503c input \u7684 value \u4e0d\u80fd\u901a\u8fc7\u8868\u5355\u6821\u9a8c<\/p>\n<p>\u5173\u952e\u5728\u4e8e\u6ca1\u80fd\u89e6\u53d1\u4eba\u5bb6\u6846\u67b6\u7684 event listener<\/p>\n<p>\u67e5\u8d44\u6599\u54af\uff0c\u53d1\u73b0\u4e86\u8fd9\u4e2a\u89e3\u7b54 https:\/\/stackoverflow.com\/a\/35807417 \u5c31\u662f\u89e6\u53d1 input \u3001keyup \u3001change \u4e8b\u4ef6\uff0c\u4f46\u5b9e\u9645\u6d4b\u8bd5\u4ecd\u7136\u4e0d\u884c\uff0c\u751a\u81f3\u6211\u628a\u5728\u5f00\u53d1\u4eba\u5458\u5de5\u5177\u80fd\u770b\u5230\u7684 event listner \u5168\u89e6\u53d1\u4e86\u4e00\u8fb9\u90fd\u6ca1\u7528 sad<\/p>\n<pre><code>function fireChangeEvents(element){     var changeEvent = null;     for(var i of [\"keypress\",\"focus\", \"input\", \"keydown\", \"keyup\", \"change\", \"blur\", \"click\", \"invalid\", \"mouseover\", \"popstate\", \"reset\", \"scroll\", \"selectionchange\", \"submit\", \"transitionend\"]){         changeEvent = document.createEvent (\"HTMLEvents\");         changeEvent.initEvent (i, true, true);         element.dispatchEvent (changeEvent);     } } fireChangeEvents(document.querySelectorAll(\"input\")[0]) <\/code><\/pre>\n<p>\u7136\u540e\u63a5\u7740\u627e\uff0c\u53d1\u73b0\u4e00\u4e2a\u80fd\u6a21\u62df\u7528\u6237\u4ea4\u4e92\u7684 npm \u5305\uff1a https:\/\/github.com\/testing-library\/user-event<\/p>\n<p>\u7136\u540e\u6298\u817e\u4e86\u4e00\u4e0b browserify \u6253\u5305\u6210\u6d4f\u89c8\u5668\u53ef\u4ee5\u7528\u7684 js \u6587\u4ef6\uff0c\u5b9e\u9645\u6d4b\u8bd5\u53ef\u884c\uff1a<\/p>\n<pre><code>userEvent.type(document.querySelectorAll(\"input\")[0], USERNAME); userEvent.type(document.querySelectorAll(\"input\")[1], PASSWORD); <\/code><\/pre>\n<p>\u95ee\u9898\u662f\u89e3\u51b3\u4e86\uff0c\u4f46\u89c9\u5f97\u4e3a\u4e86\u4e00\u4e2a\u89e6\u53d1 event \u5f15\u5165\u4e00\u4e2a 500KB \u7684 js \u6587\u4ef6\u6709\u70b9\u8822\uff08 uglify \u4e4b\u540e\u4e5f\u6709 300KB \uff09\uff0c\u95ee\u95ee\u5927\u4f6c\u4eec\u6709\u6ca1\u6709\u66f4\u597d\u7684\u65b9\u6848\uff0c\u4e0d\u9700\u8981\u5f15\u5165\u8fd9\u4e48\u91cd\u7684 js \u5e93\u7684<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>5<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3130163\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : iNaru <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             input.dispatchEvent(new Event(&#8216;input&#8217;, { bubbles: true }));                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3130164\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : cy97cool <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @iNaru \u6ca1\u6709\u7528\u5462 \u4ecd\u7136\u8981\u6c42\u201c\u8bf7\u8f93\u5165\u7528\u6237\u540d!\u201d <br \/>initEvent \u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5c31\u662f bubbles                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3130165\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : cy97cool <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/ant.design\/components\/form-cn\/<br \/>\u627e\u5230\u4e00\u4e2a\u53ef\u4ee5\u7528\u6765\u9a8c\u8bc1\u7684\u4f8b\u5b50\uff0c\u8fd9\u4e2a\u9875\u9762\u4e2d\u7684 \u5d4c\u5957\u7ed3\u6784\u4e0e\u6821\u9a8c\u4fe1\u606f \u90e8\u5206\uff0cUsername \u53f3\u8fb9\u6709\u4e2a Need Help?\u7684\u94fe\u63a5<\/p>\n<p>\u5bf9\u8fd9\u4e2a input \u53f3\u952e \u68c0\u67e5\u5143\u7d20\uff0c\u5728 Console \u91cc\u8f93\u5165 $0.value=&#8221;1&#8243; \uff0c \u7136\u540e\u70b9\u51fb\u8fd9\u4e2a\u8868\u5355\u7684 Submit\uff0c\u4f1a\u62a5\u9519\u201cUsername is required\u201d\u3002<\/p>\n<p>\u95ee\u9898\u5c31\u662f\uff1a\u5728 Console \u91cc\u8f93\u5165\u5565\u795e\u5947\u7684\u4ee3\u7801\uff0c\u80fd\u6210\u529f\u901a\u8fc7\u8fd9\u4e2a\u8868\u5355\u7684\u68c0\u67e5                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3130166\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : CoolSpring <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u662f React\uff0c\u4f3c\u4e4e\u53ef\u4ee5\u7528\u8fd9\u4e2a\uff1a https:\/\/stackoverflow.com\/questions\/23892547\/what-is-the-best-way-to-trigger-onchange-event-in-react-js<\/p>\n<p>var input = document.getElementById(&#8220;complex-form_username&#8221;);<\/p>\n<p>var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, &#8220;value&#8221;).set;<br \/>nativeInputValueSetter.call(input, &#8216;react 16 value&#8217;);<\/p>\n<p>var ev2 = new Event(&#8216;input&#8217;, { bubbles: true});<br \/>input.dispatchEvent(ev2);                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3130167\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : cy97cool <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @CoolSpring \u611f\u8c22 \u786e\u5b9e\u6709\u7528                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>tampermonkey \u5982\u4f55\u81ea\u52a8&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/149454"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=149454"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/149454\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=149454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=149454"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=149454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}