Skip to content

Instantly share code, notes, and snippets.

View shenjunru's full-sized avatar

Shen Junru shenjunru

View GitHub Profile
@shenjunru
shenjunru / strip_script.js
Last active August 29, 2015 14:15
strip script blocks form html
function strip_script(content, scripts, fix){
var so = 0, ss = 0, se, cs, ce;
var save = Object(scripts) instanceof Array;
while (-1 !== ( ss = content.indexOf('<script', ss) )) {
// update comment range, if it is before the script
while (null == ce || -1 !== ce && ss > ce) {
if (-1 !== ( cs = content.indexOf('<!--', null == ce ? so : ce) )) {
if (-1 === ( ce = content.indexOf('-->', cs) )) {
// fix comment end tag
<!DOCTYPE>
<html>
<head>
<title>Center Element by CSS: inline-block</title>
<style type="text/css">
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
@shenjunru
shenjunru / build-manifest.php
Created October 6, 2012 05:52
HTML5 Cache Manifest Builder
<?php
/*!
* HTML5 Cache Manifest Builder
* @author Shen Junru
*
* in Command Line:
* - remote=path (ex://domain/path/)
* - path/type=remote (ex: ../js/*.js=/js)
* in Browser:
* - remote=path (ex://domain/path/)
@shenjunru
shenjunru / BROWSERS-DETECT.js
Created September 30, 2012 15:23
javascript: detect browser type by features detection
// IE
// conditional comment
(function(dom){
dom.innerHTML = '<!--[if IE]><br><![endif]-->';
return !!dom.firstChild.tagName;
})(document.createElement('p'));
// Conditional Compilation
// http://msdn.microsoft.com/en-us/library/ahx1z4fs(VS.80).aspx