<commit_before>var options;
chrome.extension.sendRequest({}, function(response) {
	setAllTheSettings(response);
});

function setAllTheSettings(response) {
	options = response;
	bodyClasses = document.body.classList;
	document.body.addEventListener("DOMNodeInserted", eventDispatcher);
	if(options.circled_avatars == "true") {
		bodyClasses.add("btd-circle-avatars");
	}
	if(options.fading_pictures == "true") {
		bodyClasses.add("btd-profile-pictures-fading");
	}
	if(options.reduced_padding == "true") {
		bodyClasses.add("btd-reduced-padding");
	}
	if(options.no_columns_icons == "true") {
		bodyClasses.add("btd-no-columns-icons");
	}
}

function eventDispatcher() {
	// If the event.target is the text (TweetDeck updates timestamp at regular intervals) then we can get the .txt-mute element and tweak it in real-time
	if(event.relatedNode.className.indexOf("txt-mute") != -1 && options.timestamp != "relative") {
		timeIsNotRelative(event.relatedNode, options.timestamp);
	} 
	// If it's not a .txt-mute element, it must be a tweet or something similar, let's check it !
	else if(event.target.className && event.target.className.indexOf("stream-item") != -1) {

		// Applying the timestamp
		if(options.timestamp != "relative") {
			if(event.target.querySelector("time")){
				timeIsNotRelative(event.target.querySelector("time > *"), options.timestamp);
			}
		}

		// Tweaking the name displaying
		nameDisplay(event.target.querySelectorAll("a[rel='user']:not(.item-img)"), options.name_display);
		
		// If asked, removing t.co links
		if(options.url_redirection == "true"){
			useFullUrl(event.target);
		}

		// If asked, creating the non-pic.twitter image previews
		if(options.img_preview != "false"){
			links = event.target.querySelectorAll("p > a[data-full-url]");
			if(links.length > 0) {
			linkUrl = links[0].getAttribute("data-full-url");
				if(linkUrl.indexOf("imgur.com") != -1 && linkUrl.indexOf("/a/") == -1){
					createPreviewDiv(links[0],"imgur");
				} else if(linkUrl.indexOf("d.pr/i") != -1) {
					createPreviewDiv(links[0],"droplr");
				}
			}
		}
	} else if(event.relatedNode.classList.contains("typeahead")) {
		console.log("mention helper !");
		if(options.name_display == "username") {
			for (var i = event.relatedNode.querySelectorAll("strong.fullname").length - 1; i >= 0; i--) {
				event.relatedNode.querySelectorAll("strong.fullname")[i].remove();
			};
			for (var i = event.relatedNode.querySelectorAll("span.username").length - 1; i >= 0; i--) {
				event.relatedNode.querySelectorAll("span.username")[i].style.fontWeight= "bold";
				event.relatedNode.querySelectorAll("span.username")[i].classList.add("fullname");
				event.relatedNode.querySelectorAll("span.username")[i].classList.remove("username");
			};
		}
	}
}

function createPreviewDiv(element, provider) {
	// Getting the full URL for later
	linkURL = element.getAttribute("data-full-url");
	thumbSize = options.img_preview;

	// Creating the elements, replicating the same layout as TweetDeck's one
	previewDiv = document.createElement("div");
	previewDiv.className = "js-media media-preview position-rel btd-preview "+provider;
	previewDivChild = document.createElement("div");
	previewDivChild.className = "js-media-preview-container position-rel margin-vm";
	previewLink = document.createElement("a");
	previewLink.className = "js-media-image-link block med-link media-item media-size-"+thumbSize+"";
	// Little difference, using rel=url otherwhise TweetDeck will treat it as a "real" media preview, therefore "blocking" the click on it 
	previewLink.setAttribute("rel","url");
	previewLink.href = linkURL;
	previewLink.setAttribute("target","_blank");

	if(provider == "imgur") {
		// Imgur supported extensions (from http://imgur.com/faq#types)
		extensions = ["jpg","jpeg","gif","png","apng"];

		if(thumbSize == "small") suffix = "t";
		if(thumbSize == "medium") suffix = "m";
		if(thumbSize == "large") suffix = "l";

		var regex = new RegExp(extensions.join('|'));
		var thumbnailUrl;

		// If link has an extension, replacing it by .jpg (png would be possible, but we don't want to have big previews)
		if (regex.test(previewLink.href)) {
			for (var i = extensions.length - 1; i >= 0; i--) {
				thumbnailUrl = linkURL.replace("."+extensions[i],suffix+".jpg");
			};
		} else {
			// Even if it doesn't have any extension, putting it one at the end so we can get something
			thumbnailUrl = linkURL+suffix+".jpg";
		}

		// Replacing imgur.com by i.imgur.com and http by https
		thumbnailUrl = thumbnailUrl.replace("/imgur.com","/i.imgur.com").replace("http","https");

		// Removing the "gallery" in URLs to allow a nice preview
		if(thumbnailUrl.indexOf("gallery") != -1) {
			thumbnailUrl = thumbnailUrl.replace("/gallery","");
		}
<commit_msg>Removed the preview handling for imgur /gallery/ links, because sometimes a gallery and an image can have the same id, and that's not good.<commit_after>var options;
chrome.extension.sendRequest({}, function(response) {
	setAllTheSettings(response);
});

function setAllTheSettings(response) {
	options = response;
	bodyClasses = document.body.classList;
	document.body.addEventListener("DOMNodeInserted", eventDispatcher);
	if(options.circled_avatars == "true") {
		bodyClasses.add("btd-circle-avatars");
	}
	if(options.fading_pictures == "true") {
		bodyClasses.add("btd-profile-pictures-fading");
	}
	if(options.reduced_padding == "true") {
		bodyClasses.add("btd-reduced-padding");
	}
	if(options.no_columns_icons == "true") {
		bodyClasses.add("btd-no-columns-icons");
	}
}

function eventDispatcher() {
	// If the event.target is the text (TweetDeck updates timestamp at regular intervals) then we can get the .txt-mute element and tweak it in real-time
	if(event.relatedNode.className.indexOf("txt-mute") != -1 && options.timestamp != "relative") {
		timeIsNotRelative(event.relatedNode, options.timestamp);
	} 
	// If it's not a .txt-mute element, it must be a tweet or something similar, let's check it !
	else if(event.target.className && event.target.className.indexOf("stream-item") != -1) {

		// Applying the timestamp
		if(options.timestamp != "relative") {
			if(event.target.querySelector("time")){
				timeIsNotRelative(event.target.querySelector("time > *"), options.timestamp);
			}
		}

		// Tweaking the name displaying
		nameDisplay(event.target.querySelectorAll("a[rel='user']:not(.item-img)"), options.name_display);
		
		// If asked, removing t.co links
		if(options.url_redirection == "true"){
			useFullUrl(event.target);
		}

		// If asked, creating the non-pic.twitter image previews
		if(options.img_preview != "false"){
			links = event.target.querySelectorAll("p > a[data-full-url]");
			if(links.length > 0) {
			linkUrl = links[0].getAttribute("data-full-url");
				if(linkUrl.indexOf("imgur.com") != -1 && linkUrl.indexOf("/a/") == -1 && linkUrl.indexOf("/gallery/") == -1){
					createPreviewDiv(links[0],"imgur");
				} else if(linkUrl.indexOf("d.pr/i") != -1) {
					createPreviewDiv(links[0],"droplr");
				}
			}
		}
	} else if(event.relatedNode.classList.contains("typeahead")) {
		console.log("mention helper !");
		if(options.name_display == "username") {
			for (var i = event.relatedNode.querySelectorAll("strong.fullname").length - 1; i >= 0; i--) {
				event.relatedNode.querySelectorAll("strong.fullname")[i].remove();
			};
			for (var i = event.relatedNode.querySelectorAll("span.username").length - 1; i >= 0; i--) {
				event.relatedNode.querySelectorAll("span.username")[i].style.fontWeight= "bold";
				event.relatedNode.querySelectorAll("span.username")[i].classList.add("fullname");
				event.relatedNode.querySelectorAll("span.username")[i].classList.remove("username");
			};
		}
	}
}

function createPreviewDiv(element, provider) {
	// Getting the full URL for later
	linkURL = element.getAttribute("data-full-url");
	thumbSize = options.img_preview;

	// Creating the elements, replicating the same layout as TweetDeck's one
	previewDiv = document.createElement("div");
	previewDiv.className = "js-media media-preview position-rel btd-preview "+provider;
	previewDivChild = document.createElement("div");
	previewDivChild.className = "js-media-preview-container position-rel margin-vm";
	previewLink = document.createElement("a");
	previewLink.className = "js-media-image-link block med-link media-item media-size-"+thumbSize+"";
	// Little difference, using rel=url otherwhise TweetDeck will treat it as a "real" media preview, therefore "blocking" the click on it 
	previewLink.setAttribute("rel","url");
	previewLink.href = linkURL;
	previewLink.setAttribute("target","_blank");

	if(provider == "imgur") {
		// Imgur supported extensions (from http://imgur.com/faq#types)
		extensions = ["jpg","jpeg","gif","png","apng"];

		if(thumbSize == "small") suffix = "t";
		if(thumbSize == "medium") suffix = "m";
		if(thumbSize == "large") suffix = "l";

		var regex = new RegExp(extensions.join('|'));
		var thumbnailUrl;

		// If link has an extension, replacing it by .jpg (png would be possible, but we don't want to have big previews)
		if (regex.test(previewLink.href)) {
			for (var i = extensions.length - 1; i >= 0; i--) {
				thumbnailUrl = linkURL.replace("."+extensions[i],suffix+".jpg");
			};
		} else {
			// Even if it doesn't have any extension, putting it one at the end so we can get something
			thumbnailUrl = linkURL+suffix+".jpg";
		}

		// Replacing imgur.com by i.imgur.com and http by https
		thumbnailUrl = thumbnailUrl.replace("/imgur.com","/i.imgur.com").replace("http","https");

{'fraction_non_alphanumeric': 0.16180788590604026, 'fraction_numerical': 0.003355704697986577, 'mean_word_length': 4.5, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1308804', 'n_tokens_mistral': 3267, 'n_tokens_neox': 3001, 'n_words': 663}