Skip to content

Instantly share code, notes, and snippets.

View mohamedmansour's full-sized avatar
✔️
Available

Mohamed Mansour mohamedmansour

✔️
Available
View GitHub Profile
@mohamedmansour
mohamedmansour / gist:878614
Created March 20, 2011 19:48
Total number of hours watched on Netflix
var timings = document.querySelectorAll("#rhtable tr > td:nth-of-type(4)");
var totalHours = 0;
for (var i = 0; i < timings.length; i++) {
var timing = timings[i].innerHTML.split(":");
totalHours += parseFloat(timing[0]) + (parseFloat(timing[1]) / 60) + (parseFloat(timing[1]) / 3600);
}
alert("Hours watched: " + totalHours);
@mohamedmansour
mohamedmansour / cs.js
Created June 19, 2011 13:53
Disqus Chrome Extension Injection
// We just need to check if the IFrame origin is from discus.com
if (location.hostname.indexOf('.disqus.com') != -1) {
// Extract the textarea (there must be exactly one)
var commentBox = document.querySelector('#comment');
if (commentBox) {
// Inject some text!
commentBox.innerText = 'Google Chrome Injected!';
}
}
@mohamedmansour
mohamedmansour / background.html
Created June 30, 2011 00:14
Local Storage Message Passing Chrome Extension
<!doctype html>
<script>
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.sendRequest(tab.id, {method: "getLocalStorage"}, function(response) {
var myObjectRetrieved = JSON.parse(response.data);
console.log(myObjectRetrieved);
});
});
// Automatically inject all pages with the content script when the extension
@mohamedmansour
mohamedmansour / inject.js
Created July 11, 2011 03:14
Amanda Hangouts!
alert('Hello!');
@mohamedmansour
mohamedmansour / click.js
Created July 16, 2011 01:09
Simulate a click in JavaScript for Google+ Share
function simulateClick(element) {
var clickEvent = document.createEvent("MouseEvents")
clickEvent.initEvent("mousedown", true, true)
element.dispatchEvent(clickEvent);
clickEvent = document.createEvent("MouseEvents")
clickEvent.initEvent("click", true, true)
element.dispatchEvent(clickEvent);
clickEvent = document.createEvent("MouseEvents")
@mohamedmansour
mohamedmansour / similar.sql
Created August 6, 2011 01:16
Which users are similar to me
SELECT
@UserBit_50 =
IFNULL(
convert(profilevalue_50, unsigned)
,0
)
FROM
se_profilevalues
WHERE
profilevalue_user_id = 1;
@mohamedmansour
mohamedmansour / similar.sql
Created August 6, 2011 01:17
How similar is this user?
SELECT
@UserBit_50 as 'UserBit_50 (This Should not Be Null!)',
SUM(
(
convert( IFNULL(profilevalue_50, 0) , unsigned ) &
40988 /*@UserBit_50*/) > 0
) / (
SELECT COUNT(*) FROM se_profilevalues
) AS 'Avg Intersection'
FROM
@mohamedmansour
mohamedmansour / class.definition.inc.php
Created August 19, 2011 19:06
Acronym Definition class to add acyronyms to the first occurring word in the Acronym list.
<?
/**
*
* PHP 5.1 Acronym Definition Class
* Adds acronymn tags to the first occuring word which is in the Acronym List
* Very nice package which allows your users to see what the abbreviated word is.
*
* @name
* DefinitionList
* @version
javascript:(function(){
var overlay = document.getElementById('mw-sopaOverlay');
overlay.parentNode.removeChild(overlay);
var pages = ['mw-page-base', 'mw-head-base', 'content', 'mw-head', 'mw-panel', 'footer'];
var i = 0;
for (i = 0; i < pages.length; i++) {
var pageName = pages[i];
var page = document.getElementById(pageName);
page.setAttribute('style', '');
page.style.display = 'block';
@mohamedmansour
mohamedmansour / manifest.json
Created February 12, 2012 00:13
Chrome Extension to transfer the current selected webpage text to the popup
{
"name": "Selected Text",
"version": "0.1",
"description": "Selected Text",
"browser_action": {
"default_title": "Selected Text",
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [