Skip to content
Permalink
Browse files

Add the "stories" support

  • Loading branch information
mittya committed Nov 18, 2017
1 parent 6abcc05 commit 55d8b017bdfd958d10741029cf2043384ce1824a
@@ -1,7 +1,7 @@
.PHONY: firefox, chrome
.PHONY: ff, ch

firefox:
ff:
cd firefox && zip -r -X firefox.zip *

chrome:
ch:
cd chrome && zip -r -X chrome.zip *
@@ -4,7 +4,7 @@

"name": "__MSG_extName__",
"description": "__MSG_extDesc__",
"version": "1.7.6",
"version": "1.8.0",

"browser_action": {
"default_icon": {
@@ -25,56 +25,68 @@ Element.prototype.parents = function(selector) {
*/
if (window.location.pathname === '/') {
// Home page
var _box = document.querySelector('#react-root > section > main > section > div > div > div');
var _box_home = document.querySelector('#react-root > section > main > section > div > div > div');

// Logged in
if (_box) {
findMedia(_box);
if (_box_home) {
findMedia(_box_home);
}
} else if (window.location.pathname.match('/p/')) {
// Detail page

// TODO: 内页有时获取不到 djalog
setTimeout(function() {
var _box = '';
var _box_detail = '';

setTimeout(function() {
// first click is absolute,second is dialog
if (document.querySelector('div[role="dialog"]')) {
// djalog
_box = document.querySelector('div[role="dialog"]').querySelector('article');
_box_detail = document.querySelector('div[role="dialog"]').querySelector('article');
findMedia(_box_detail);
} else {
// absolute
_box = document.querySelector('#react-root > section > main article');
_box_detail = document.querySelector('#react-root > section > main article');
findMedia(_box_detail);
}
}, 1000); // TODO: 初次点击缩略图不能捕捉 dialog,这里临时用 setTimeout 修复

} else if (window.location.pathname.match('/stories/')) {
// Stories page

// TODO: remove setTimeout
setTimeout(function() {
var _box_story = document.querySelector('#react-root > section div._ni05h');

findMedia(_box);
}, 1000);
if (_box_story) {
findMedia(_box_story, 'stories');
}
}, 50);

}


function findMedia(box) {
var _box = box;
function findMedia(box, way) {
var _box = box, _way = way;
var _parent, _url, _username;

_box.addEventListener('mouseover', function(event) {

// img class: _2di5p
if (event.target.className === '_2di5p') {

if (event.target.width < 300) {
// thumb
return;
}
// disabled on the thumbnail page
if (event.target.width > 300) {
_parent = event.target.parentNode;
_url = event.target.src;
_url = _url.replace(/[a-zA-Z][0-9]+x[0-9]+\//, '');
_username = '';

_parent = event.target.parentNode;
_url = event.target.src;
_url = _url.replace(/[a-zA-Z][0-9]+x[0-9]+\//, '');
_username = '';
if (_parent.parents('article')[0].querySelector('._2g7d5')) {
_username = _parent.parents('article')[0].querySelector('._2g7d5').title;
if (_parent.parents('article')[0].querySelector('._2g7d5')) {
_username = _parent.parents('article')[0].querySelector('._2g7d5').title;
}

addBtn(_parent, _url, _username);
}

addBtn(_parent, _url, _username);
}

// video parents class: _7thjo
@@ -90,6 +102,30 @@ function findMedia(box) {

addBtn(_parent, _url, _username);
}

// Stories video
if (_way === 'stories' && event.target.tagName === 'VIDEO') {
_parent = event.target.parentNode;
_url = _parent.querySelector('video > source').src;
_url = _url.replace(/[a-zA-Z][0-9]+x[0-9]+\//, '');
_username = _parent.parents('section')[0].querySelector('._2g7d5').title;

addBtn(_parent, _url, _username);

return false;
}

// Stories Picture
if (_way === 'stories' && event.target.tagName === 'IMG') {
_parent = event.target.parentNode;
_url = _parent.querySelector('img').src;
_url = _url.replace(/[a-zA-Z][0-9]+x[0-9]+\//, '');
_username = _parent.parents('section')[0].querySelector('._2g7d5').title;

addBtn(_parent, _url, _username);

return false;
}
});
}

@@ -103,7 +139,12 @@ function addBtn(parent, url, username) {
}

var _btn = document.createElement('button');
_btn.className = 'downloadBtn';

if (window.location.pathname.match('/stories/')) {
_btn.className = 'downloadBtn inStories';
} else {
_btn.className = 'downloadBtn';
}

_btn.addEventListener('click', function(event) {
event.stopPropagation();
@@ -29,12 +29,23 @@
background-image: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/PjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+PHN2ZyB3a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6jl3c: VIDEO parent
._2us5i Stories parent
*/
._4rbun:hover .downloadBtn,
._6jl3c:hover .downloadBtn {
._6jl3c:hover .downloadBtn,
._2us5i:hover .downloadBtn {
opacity: 1;
}

@@ -44,7 +55,7 @@
}


/* pic cover */
._si7dy {
._si7dy /* pic cover */,
._o95x1 /* stories cover */ {
display: none !important;
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -3,7 +3,7 @@

"name": "IGHelper",
"description": "Easily download Instagram pictures and videos.",
"version": "1.7.6",
"version": "1.8.0",

"browser_action": {
"default_icon": {
@@ -13,9 +13,9 @@
},

"icons": {
"16": "icons/icon_512.png",
"48": "icons/icon_512.png",
"128": "icons/icon_512.png"
"16": "icons/icon_16.png",
"48": "icons/icon_48.png",
"128": "icons/icon_128.png"
},

"background": {
@@ -25,56 +25,68 @@ Element.prototype.parents = function(selector) {
*/
if (window.location.pathname === '/') {
// Home page
var _box = document.querySelector('#react-root > section > main > section > div > div > div');
var _box_home = document.querySelector('#react-root > section > main > section > div > div > div');

// Logged in
if (_box) {
findMedia(_box);
if (_box_home) {
findMedia(_box_home);
}
} else if (window.location.pathname.match('/p/')) {
// Detail page

// TODO: 内页有时获取不到 djalog
setTimeout(function() {
var _box = '';
var _box_detail = '';

setTimeout(function() {
// first click is absolute,second is dialog
if (document.querySelector('div[role="dialog"]')) {
// djalog
_box = document.querySelector('div[role="dialog"]').querySelector('article');
_box_detail = document.querySelector('div[role="dialog"]').querySelector('article');
findMedia(_box_detail);
} else {
// absolute
_box = document.querySelector('#react-root > section > main article');
_box_detail = document.querySelector('#react-root > section > main article');
findMedia(_box_detail);
}
}, 1000); // TODO: 初次点击缩略图不能捕捉 dialog,这里临时用 setTimeout 修复

} else if (window.location.pathname.match('/stories/')) {
// Stories page

// TODO: remove setTimeout
setTimeout(function() {
var _box_story = document.querySelector('#react-root > section div._ni05h');

findMedia(_box);
}, 1000);
if (_box_story) {
findMedia(_box_story, 'stories');
}
}, 50);

}


function findMedia(box) {
var _box = box;
function findMedia(box, way) {
var _box = box, _way = way;
var _parent, _url, _username;

_box.addEventListener('mouseover', function(event) {

// img class: _2di5p
if (event.target.className === '_2di5p') {

if (event.target.width < 300) {
// thumb
return;
}
// disabled on the thumbnail page
if (event.target.width > 300) {
_parent = event.target.parentNode;
_url = event.target.src;
_url = _url.replace(/[a-zA-Z][0-9]+x[0-9]+\//, '');
_username = '';

_parent = event.target.parentNode;
_url = event.target.src;
_url = _url.replace(/[a-zA-Z][0-9]+x[0-9]+\//, '');
_username = '';
if (_parent.parents('article')[0].querySelector('._2g7d5')) {
_username = _parent.parents('article')[0].querySelector('._2g7d5').title;
if (_parent.parents('article')[0].querySelector('._2g7d5')) {
_username = _parent.parents('article')[0].querySelector('._2g7d5').title;
}

addBtn(_parent, _url, _username);
}

addBtn(_parent, _url, _username);
}

// video parents class: _7thjo
@@ -90,6 +102,30 @@ function findMedia(box) {

addBtn(_parent, _url, _username);
}

// Stories video
if (_way === 'stories' && event.target.tagName === 'VIDEO') {
_parent = event.target.parentNode;
_url = _parent.querySelector('video > source').src;
_url = _url.replace(/[a-zA-Z][0-9]+x[0-9]+\//, '');
_username = _parent.parents('section')[0].querySelector('._2g7d5').title;

addBtn(_parent, _url, _username);

return false;
}

// Stories Picture
if (_way === 'stories' && event.target.tagName === 'IMG') {
_parent = event.target.parentNode;
_url = _parent.querySelector('img').src;
_url = _url.replace(/[a-zA-Z][0-9]+x[0-9]+\//, '');
_username = _parent.parents('section')[0].querySelector('._2g7d5').title;

addBtn(_parent, _url, _username);

return false;
}
});
}

@@ -103,7 +139,12 @@ function addBtn(parent, url, username) {
}

var _btn = document.createElement('button');
_btn.className = 'downloadBtn';

if (window.location.pathname.match('/stories/')) {
_btn.className = 'downloadBtn inStories';
} else {
_btn.className = 'downloadBtn';
}

_btn.addEventListener('click', function(event) {
event.stopPropagation();

0 comments on commit 55d8b01

Please sign in to comment.
You can’t perform that action at this time.