Develop your own blog forwarding plug-in (cross-origin) and forwarding

Source: Internet
Author: User
Tags password protection

Develop your own blog forwarding plug-in (cross-origin) and forwarding

Next, I mentioned "blog backup gadgets 3" in the previous article, "I actually thought about why do I have to forward a blog on a local client, can js be used directly on the blog garden page to achieve the goal. I think so. I haven't tried it yet. After I finish writing this blog, I will try it ..". The idea is naive and the reality is cruel. I thought that the content of the current page can be published by direct ajax asynchronous post request. However, the problem arises. The webpage domain name we browsed is cnblogs.com, and the domain name we published in the background is I .cnblogs.com. Cross-origin. Now that the problem has come, we can't leave it alone. The world of programs cannot be done. Jsonp is dedicated to doing this. (Jsonp Data Portal ). Why not use blog Backup Tool 3 because it belongs to CS. It would be nice to have a button for one-click forwarding directly on the browser page. It seems that Chrome plug-ins can specifically do such bad things. (Chrome plug-in introduces the portal ). Now, we have two important points.

Next, let's talk about the main implementation idea. First, you can use the plug-in to find a block location for yourself on the browser page (add a div ). Then, you can enter the user name and password in the div to log on and obtain the document type. Next, we will publish the content of the current page through the jsonp cross-origin to our own development background for publishing ~ Is it easy? Haha, actually I think it is quite difficult. Many problems were encountered. Now, it is estimated that there are still many bugs.

Okay. Let's take a look. Do you feel good? If you are aware of security issues, I will open all the source code below. You can make improvements. Pai_^

1. Open up a space

The content_script.js configured in the plug-in content_script allows you to directly operate on the current browser page in content_script.js. Haha, this is enough. I don't want to go anywhere. Well, we can open up a space for ourselves to perform the desired operations.

Var mydata = ""; mydata + = "& url =" + document. location. href; mydata + = "& type = mytype"; mydata + = "& tag = mytag"; var html = "<div id = 'chrome _ test_div 'style = 'display: none; background-color: # 0094ff; position: fixed; top: 0px; left: 0px; width: 100%; z-index: 11' >\< table style = 'width: 100% '> \ <tr >\< td> User Name: </td> \ <td> <input id = 'chrome _ test_user 'type = 'text' value = ''/> </td> \ <td> password: </td> \ <td> <input id =' Chrome_test_pass 'Type = 'Password' value = ''/> </td> \ <a href = 'javascript: void (0 ); 'id = 'chrome _ test_a '> \ login \ </a >\</td >\< td> \ article: \ </td >\< span id = 'chrome _ content_title '> </span >\</td >\\ <td> personal category: </td >\< select id = 'pop _ sel_type_text '> </select >\</td >\< td >\tag: \ </td> \ <input type = 'text' value = ''list = 'pop _ sel_tag_text 'id = 'id _ pop_sel_tag_text'> \ <input type = 'ddyd' id = 'myddyd' />\<! -- <Datalist id = 'pop _ sel_tag_text '> </datalist> -- >\</td> \ <td colspan = '2'> <input type = 'button' id = 'chrome _ test_button 'value = 'one-click forwarding'/> </td> \ <td id = 'chrome _ meg_td '> </td> \ </tr> \ </ table> \ <script src =' https://git.oschina.net/zhaopeiym/Demo/raw/master/resource/cnblogs/cnblog.Chrome.js?v=123 '> </Script >\</div> "; $ (" body "cmd.prepend(html#.css (" margin-top "," 70px "); $ (" # chrome_content_title "). text ($ ("# cb_post_title_url "). text (); document. body. scrollTop = 30; window. onscroll = function () {if (true) {var top = document. body. scrollTop; if (top <= 0) {$ ("# chrome_test_div "). slideDown (200);} else if (top> = 30) {$ ("# chrome_test_div "). slideUp (400 );}}}

 

Add a div directly and add a table to the div. Draw the username, password, article title, background post type, tag, and so on to log on.

2. log on to get all your article categories. 1. Send a request using jsonp

I wonder if the students have noticed a section in the above Code

<Script src = 'https: // git.oschina.net/zhaopeiym/Demo/raw/master/resource/cnblogs/cnblog.Chrome.js? V = 123 '> </script>
Yes, so the js on the current operation page is under this path.

function chrome_test_login() {    var username = $("#chrome_test_user").val();    var password = $("#chrome_test_pass").val();    var Section_url = "&username=" + username + "&password=" + password;    $.getJSON(getjsonUrl + '/BolghelpWeb/Handler1.ashx?OperationCMD=login' + Section_url + '&callback=?', function (data) {        test(data);    });}

 

Login js. Ajax jsonp is quite convenient to use.

2. Background code logon and document retrieval Classification

Logon:

/// <Summary> /// log on /// </summary> /// <param name = "context"> </param> public void PostLogin (HttpContext context, string username, string password) {username = context. request. queryString ["username"]; password = context. request. queryString ["password"]; string loginurl =" http://passport.cnblogs.com/login.aspx?ReturnUrl=<ALIMT > http://www.cnblogs.com/ </Alsce> "; // string result = htmlWeb. load (loginurl ). documentNode. innerHtml; String _ EVENTVALIDATION = new Regex ("id = \" _ EVENTVALIDATION \ "value = \"(. *?) \""). Match (result ). groups [1]. value; String _ VIEWSTATE = new Regex ("id = \" _ VIEWSTATE \ "value = \"(. *?) \ ""). Match (result). Groups [1]. Value; String delimiter = new Regex ("id = \" LBD_VCID_c_login_logincaptcha \ "value = \"(.*?) \""). Match (result ). groups [1]. value; StringBuilder str_content = new StringBuilder (); str_content.Append (@ "_ EVENTTARGET ="); str_content.Append (@ "& __ EVENTARGUMENT = "); str_content.Append (@ "& __ VIEWSTATE =" + System. web. httpUtility. urlEncode (_ VIEWSTATE, Encoding. UTF8); str_content.Append (@ "& __ VIEWSTATEGENERATOR = C2EE9ABB"); str_content.Append (@ "& __ EVENTVALIDATION =" + System. web. httpUtility. urlEncode (_ EVENTVALIDATION, Encoding. UTF8); str_content.Append (@ "& tbUserName =" + System. web. httpUtility. urlEncode (username, Encoding. UTF8); str_content.Append (@ "& tbPassword =" + password); str_content.Append (@ "& Signature =" + signature); str_content.Append (@ "& Signature = "); str_content.Append (@ "& btnLogin = login"); str_content.Append (@ "& txtReturnUrl = http://www.cnblogs.com/"); httphelp. postHtml (loginurl, null, str_content.ToString (), Encoding. UTF8, true );}

 

Document category:

/// <Summary> // obtain the document type /// </summary> /// <param name = "context"> </param> public void PostGetType (HttpContext context) {PostLogin (context, "", ""); string TypeUrl =" http://i.cnblogs.com/EditArticles.aspx?opt=1 "; // Address var typeHtml = httphelp. postHtml (TypeUrl, null, "", Encoding. UTF8, true); HtmlAgilityPack. htmlDocument response = new HtmlDocument (); response. loadHtml (typeHtml); var html_trS = response. documentNode. selectNodes ("// * [@ id = 'editor _ Edit_APOptions_Advancedpanel1_cklCategories ']/tr"); List <object> objs = new List <object> (); foreach (var item in html_trS) {var html_tdS = item. selectNodes (item. XPa Th + "/td"); foreach (var item_td in html_tdS) {if (item_td.SelectSingleNode (item_td.XPath + "/input ")! = Null) {var value = item_td.SelectSingleNode (item_td.XPath + "/input "). attributes ["value"]. value; var name = item_td.SelectSingleNode (item_td.XPath + "/input "). attributes ["name"]. value; var text = item_td.SelectSingleNode (item_td.XPath + "/label "). innerText; objs. add (new {value = value, text = text, name = name}) ;}} context. response. contentType = "application/json"; string callback = context. request. queryString ["callback"]; context. response. write (callback + "(" + objs. toJson () + ")");}

 

OK. log on here and get all the article types.

3. One-click release

In fact, it was logged on again before the release. Why? Because publishing requires logon, the previous login request was made. The session of the last request cannot be read. It may be because of cross-origin requests. There is no way, so log on again. The logon countermeasure is independent. It's just a computer multi-officer.

1. The homepage obtains the body content to be forwarded on the front-end page.
// One-click forwarding $ ("# chrome_test_button "). click (function () {$ ("# chrome_meg_td" ).html (""); var type = $ ("# pop_sel_type_text "). val (). split ('%') [0]; var name = $ ("# pop_sel_type_text "). val (). split ('%') [1]; var username = $ ("# chrome_test_user "). val (); var password = $ ("# chrome_test_pass "). val (); var tag = $ ("# id_pop_sel_tag_text "). val (); var Section_url = "& type =" + type + "& tag =" + tag + "& name =" + name + "& pas Sword = "+ password +" & username = "+ username; $. getJSON (getjsonUrl + '/BolghelpWeb/Handler1.ashx? OperationCMD = Publishing & callback =? '+ Section_url +' & url = '+ document. location. href, function (data) {$ ("# chrome_meg_td" ).html ("published successfully ~ <A href = 'HTTP: // I .cnblogs.com/EditArticles.aspx' target = '_ blank'> View in the background ~ </A> "); $ (" # chrome_test_div a ").css (" color "," # fff ");});});

 

2. Then it is published in the background.
/// <Summary> /// publish /// </summary> /// <param name = "context"> </param> public void PostPublishing (HttpContext context) {string url =" http://i.cnblogs.com/EditArticles.aspx?opt=1 "; // Address string callback = context. request. queryString ["callback"]; string mydataurl = context. request. queryString ["url"]; string mydatatype = context. request. queryString ["type"]; string mydatatag = context. request. queryString ["tag"]; string mydataname = context. request. queryString ["name"]; PostLogin (context, "", ""); var html = httphelp. postHtml (url, null, "", Encoding. UTF8, true); String _ VIEWSTAT E = new Regex ("id = \" _ VIEWSTATE \ "value = \"(.*?) \""). Match (html ). groups [1]. value; string title = "test", body = "test"; GetRequest (mydataurl, ref body, ref title ); body + = "</br >====================================== = <a href = '"+ mydataurl +" 'target =' _ blank '> original link </a> = This article is composed of <a href =' http://www.cnblogs.com/zhaopei/ 'Target = '_ blank'> blog forwarding plug-in </a> forwarding ====================== ========== "; stringBuilder str_content = new StringBuilder (); str_content.Append (@ "_ VIEWSTATE =" + System. web. httpUtility. urlEncode (_ VIEWSTATE, Encoding. UTF8); // The casually classified information is related to _ VIEWSTATE, so it is difficult to classify str_content.Append (@ "& __ VIEWSTATEGENERATOR = FE27D343 "); // FE27D343 0512620B str_content.Append (@ "& Editor $ Edit $ txbTitle =" + System. web. httpUtility. urlEncode ("[]" + title, Encoding. UTF8); str_content.Append (@ "& Editor $ Edit $ EditorBody =" + System. web. httpUtility. urlEncode (body, Encoding. UTF8); str_content.Append (@ "&" + mydataname + "=" + mydatatype); str_content.Append (@ "& Editor $ Edit $ Advanced $ ckbPublished = on "); // publish str_content.Append (@ "& Editor $ Edit $ Advanced $ chkDisplayHomePage = on "); // The blog homepage displays str_content.Append (@ "& Editor $ Edit $ Advanced $ chkComments = on "); // allow comment str_content.Append (@ "& Editor $ Edit $ Advanced $ chkMainSyndication = on "); // str_content.Append (@ "& Editor $ Edit $ Advanced $ txbEntryName =") in RSS; // friendly address name, it can only contain letters, numbers, hyphens (-), and underscores (_). It cannot exceed 150 characters, including str_content.Append (@ "& Editor $ Edit $ Advanced $ txbExcerpt = "); // insert str_content.Append (@ "& Editor $ Edit $ Advanced $ txbTag =" + mydatatag) to the right of the abstract ); // Tag str_content.Append (@ "& Editor $ Edit $ Advanced $ tbEnryPassword ="); // password protection str_content.Append (@ "& Editor $ Edit $ lkbPost = publish "); var srcString = httphelp. postHtml (url, null, str_content.ToString (), Encoding. UTF8, true); // publish context. response. contentType = "application/json"; // output: callback function name (json data) if (srcString. contains ("published successfully") context. response. write (callback + "('OK')"); else context. response. write (callback + "('no ')");}

 

This is basically done. Haha ~

Iv. How to Use

Someone may not know how to install the plug-in. 360 you only need to drag the plug-in to the browser. If it is Google's original browser, drag it to chrome: // extensions. If there is still a problem, how can Baidu install the plug-in.

If you do not want to read the source code, you can directly download the plug-in for use. After installation, open any blog post page and roll the scroll bar to the top to see the effect (the effect is relatively hidden, in order not to affect the normal browsing of page content ). 【]

 

V. Download source code

Download all source code (including the plug-in source code, background source code, and referenced external js Code ). Old rules. If it is useful to you, And you download it again. Please give me a thumbs up ~~

 

PS: This article was originally written at,. It will be published the next day. However, the next day, I found that I could not log on. In the past, the logon method of the blog Park was modified. After a long time, I did not know how to log on. I did not intend to see an article and used my ideas for reference. Done !! This is mainly for fun, and many other functions will be improved later. For example, remember the password, automatically log on to retrieve the classified data, and of course there are still many bugs. Let's do this first, and then modify it slowly.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.