Andrew's Facebook Tagged Photos Downloader

Download all Facebook photos that you are tagged in.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name			Andrew's Facebook Tagged Photos Downloader
// @include			https://www.facebook.com/*/allactivity?privacy_source=activity_log&log_filter=cluster_200
// @require			http://code.jquery.com/jquery-1.7.1.min.js
// @grant			none
// @version			2.0
// @description		Download all Facebook photos that you are tagged in.
// @namespace https://greasyfork.org/users/36399
// ==/UserScript==

/*
 * For jQuery Conflicts.
 */
this.$ = this.jQuery = jQuery.noConflict(true);

// Variables
var fbname = document.title;
var firstrun = false;
var retry = 0;
var retries = 10;

// Inject buttons into page
$(document).ready(function() {
    $('#pagelet_main_column_personal div [class="_2o3t fixed_elem"] div[class="clearfix uiHeaderTop"]').append('<input type="button" id="andrewfbdl" value="Download Photos"><style>.fbprocessed { background-color: #9AFF9A; }</style>');
    $('#andrewfbdl').click(triggerdl);
});
function triggerdl() {
	if (confirm('Are you sure you wish to continue? Chrome may tell you that this page is attempting to download multiple files: please click on Allow. After you do so, please avoid scrolling this page.')) {
		inited = false;
		firstrun = false;
		retry = 0;
		andrewhandler();
	}
}

// Behold: the master function.
function andrewhandler() {
	if (!firstrun) {
		scrollTo(0, 0);
		firstrun = true;
	}
	if (retry < retries) {
		scrollTo(0, $(document).scrollTop()+$(window).height());
		if (!$("#fbTimelineLogBody div._5shk:not(.fbprocessed)").length) {
			if ($(window).scrollTop() + $(window).height() == $(document).height()) {
				retry++;
				console.log('Seems to be done. '+retry+'/'+retries);
			}
			setTimeout(function() { andrewhandler(); }, 2000);
		} else {
			retry = 0;
			contents = $("#fbTimelineLogBody div._5shk:not(.fbprocessed):first div._42ef").text();
			if (contents.indexOf(fbname+' was tagged in') != -1 && contents.indexOf(' photo.') != -1) {
				dlphoto();
			} else {
				//console.log('> Not a relevant activity, skipping.');
				$("#fbTimelineLogBody div._5shk:not(.fbprocessed):first").addClass('fbprocessed');
				andrewhandler();
			}
		}
	} else {
		alert('Done scrolling! Please wait for all photos to be downloaded.');
	}
}

function dlphoto() {
	setTimeout(andrewhandler, 2000);
	code = $("#fbTimelineLogBody div._5shk:not(.fbprocessed):first td._5ep6 a img").attr('src');
	regexp = /\/[0-9]+_([0-9]+)_[0-9]+_/g;
	match = regexp.exec(code);
	if (match[1]) {
		$("body").append("<iframe class='picdl' src='https://www.facebook.com/photo/download/?fbid="+match[1]+"' style='display: none;'></iframe>");
	}
	$("#fbTimelineLogBody div._5shk:not(.fbprocessed):first").addClass('fbprocessed');
}