Parsing of petal collection js

Source: Internet
Author: User

Step 1: Favorites section js

javascript:void(function(d,a,c,b){a[c]&&typeof a[c].showValidImages=='function'?a[c].showValidImages():(b=a.createElement('script'),b.id='huaban_script',b.setAttribute('charset','utf-8'),b.src='http://huaban.com/js/pinmarklet.js?'+Math.floor(+new Date/1E7),a.body.appendChild(b))}(window,document,'__huaban'));

If JavaScript has been loaded, run the showValidImages () method.
No, load js: http://huaban.com/js/pinmarklet.js
The img under tag a can be identified.

Step 2: extract pinmarklet. js
Save the online JavaScript code to the local huaban. js file.
43 K, one thousand lines of code, after initial compression.
From the effect of the first step, the function is to traverse the page, assemble it into a collection page, and then submit the collection.

Clue: variable "_ huaban" var global = "_ huaban ";
Document [global]. _ loaded =! 0,
Document [global]. showValidImages = showImagesAndInitPinBtn

_ Loaded initialization tag.

Clue: showValidImages method.
Document [global]. showValidImages = showImagesAndInitPinBtn

Method 1: showImagesAndInitPinBtn has obvious literal meaning. A good name.
Var a = getCurrentPageImagesWithEncapsulation ();
ShowImages (a), initPinBtn (a), window. scroll (0, 0)
A's data structure:

w=242 h=284 src=http://s4.42qu.us/img/jpg/book/3.jpg img=[object HTMLImageElement] alt= img2=[object HTMLImageElement] _parentNode=null
[{container:c,w:b.width,h:b.height,src:b.src,img:b,description:e+(d&&d.innerText||""),img2:b}]

Method 2: getCurrentPageImagesWithEncapsulation
Initial Parameter
Var _ document = d | document; eImages = eImages | [], opts = opts || {};
Traverse img

for(i=0;i<_document.images.length;i++){
var img=_document.images[i];
//alert(img);//[object HTMLImageElement]
}
isValidImage(img)&&(img=encapsulateImage(img),opts&&(img._parentNode=opts.parentNode||null),eImages.push(img))
function isValidImage(a){return a.style.display=="none"||a.className=="ImageToPin"||a.width<100||a.height<100?!1:!0}

If class ImageToPin is added to the img, the fate of being caught by the petals can be skipped. :)

GetVideoOnCustomerPage (_ document, eImages );
Processing of some videos.

EImages. push (img)

Traverse the background image.
Checkbgimgs

Filters
Bgimgs

Traverse iframes

var iframes=_document.getElementsByTagName("iframe");
for(var i=0;i<iframes.length;i++)

Method 3: function showImages ()
C. onclick = function () {return pinImage (a), B ()};

Method 4: function initPinBtn (a) {generatePinBtn (), registerImagesForPinBtn ()}

Method 5: generatePinBtn generate collection button.

Method 6: registerImagesForPinBtn (a) registers a mouse event.

Method 7: Cancel button:

var b=function(){
return c.parentNode.removeChild(c),
d.parentNode.removeChild(d),
showingImage=!1,
selectedText="",
showFlash(),
window.scroll(0,lastScrollY),
!1
},

Method 8: Collection button: pinImage
Http://www.w3school.com.cn/htmldom/met_win_open.asp

var e={
media:a.big_img?a.big_img.src:d.src,
url:c,
w:a.big_img?a.big_img.width:d.width,
h:a.big_img?a.big_img.height:d.height,
alt:d.alt,
title:a.title||document.title,
description:a.description||"",
media_type:a.media_type||"",
video:a.video||""
};

Global parameters:

Var siteDomain = "huaban.com", primary domain
ImageRoot = "http: //" + siteDomain + "/img", image path
BookmarkletUrl = "http: //" + siteDomain + "/bookmarklet/", bookmarklet path
DomChanged =! 1,
SelectedText = "",
LastScrollY = 0,
IsShareBtn =! 1,
PinBtn = null,
HidePinBtnTimer = null,
CurrentImage = null,
ImageDesc = "",
ShowingImage =! 1,
ItemUrl = "",
Skip =! 1,
Skiphrefs = ["http://www.diandian.com/wall"];

Tip 1:
(Function () {alert ("test ");})();
Define methods and run them directly. The advantage is that some temporary variables are circled and cannot conflict with other codes.

Tip 2: alert ("\ u4f60 \ u73b0 ");
Avoid Chinese Characters in js files.

Tip 3 :! 0 instead of true

Tip 4: | & syntax.

Basic Methods:
Function isIE () {return/msie/I. test (navigator. userAgent )&&! /Opera/I. test (navigator. userAgent )}
Function isSafari () {return/Safari/. test (navigator. userAgent )&&! /Chrome/. test (navigator. userAgent )}
Function isPinable (a) determines whether the LAN address is used.
Function generateTag (a, B) {var c = document. createElement (B | "div"); return c. id = global + "_" + a, c} generates a node.

Regular Expression:
Http://hzjavaeyer.group.iteye.com/group/wiki/2276-JavaScript-Core

Look at the js Code and use MyEclipse, which has the corresponding functions of brackets.

Suspect: A lot of ',' is used in the code. I do not know the advantages of the comparison.

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.