noreferrer 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -0
- data/lib/noreferrer.rb +4 -0
- data/noreferrer.gemspec +16 -0
- data/vendor/assets/javascripts/noreferrer.js +118 -0
- metadata +49 -0
data/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
noreferrer
|
2
|
+
==========
|
3
|
+
|
4
|
+
Removes referrer information on an html link
|
5
|
+
|
6
|
+
$('a').noreferrer(<array of strings to be regex matched with link hrefs>)
|
7
|
+
|
8
|
+
Example:
|
9
|
+
The following exmaple will intercept and remove the referrer information to any links that link to google.
|
10
|
+
|
11
|
+
$(document).ready(function(){
|
12
|
+
$('a').noreferrer(['google', 'yahoo.com']);
|
13
|
+
});
|
data/lib/noreferrer.rb
ADDED
data/noreferrer.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "noreferrer"
|
7
|
+
gem.version = 0.1
|
8
|
+
gem.authors = ["Rodney Carvalho"]
|
9
|
+
gem.email = ["rcarvalho@atlantistech.com"]
|
10
|
+
gem.description = "Removes referrer information on an html link."
|
11
|
+
gem.summary = "Removes referrer information on an html link."
|
12
|
+
gem.homepage = "https://github.com/rjcarvalho/noreferrer"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
/*
|
2
|
+
* Guardian - jQuery plugin for removing referrers in links
|
3
|
+
*
|
4
|
+
* Copyright (c) 2014 Rodney Carvalho
|
5
|
+
*
|
6
|
+
* Dual licensed under the MIT and GPL licenses:
|
7
|
+
* http://www.opensource.org/licenses/mit-license.php
|
8
|
+
* http://www.gnu.org/licenses/gpl.html
|
9
|
+
*
|
10
|
+
*/
|
11
|
+
|
12
|
+
(function($){
|
13
|
+
NoReferrer = {
|
14
|
+
init: function(matches){
|
15
|
+
NoReferrer.Browser.init();
|
16
|
+
if(matches != undefined){
|
17
|
+
for(i=0;i<matches.length;i++){
|
18
|
+
matches[i]
|
19
|
+
}
|
20
|
+
}
|
21
|
+
$('a').on('click', function(e){
|
22
|
+
if(matches == undefined){
|
23
|
+
NoReferrer.Link.go($(this).attr('href'));
|
24
|
+
return false;
|
25
|
+
}
|
26
|
+
else{
|
27
|
+
for(i=0;i<matches.length;i++){
|
28
|
+
if(new RegExp(matches[i]).test($(this).attr('href'))){
|
29
|
+
NoReferrer.Link.go($(this).attr('href'));
|
30
|
+
return false;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
});
|
35
|
+
},
|
36
|
+
Browser: {
|
37
|
+
browser: {},
|
38
|
+
init: function(){
|
39
|
+
matched = NoReferrer.Browser.uaMatch( navigator.userAgent );
|
40
|
+
|
41
|
+
if ( matched.browser ) {
|
42
|
+
NoReferrer.Browser.browser[ matched.browser ] = true;
|
43
|
+
NoReferrer.Browser.browser.version = matched.version;
|
44
|
+
}
|
45
|
+
|
46
|
+
// Chrome is Webkit, but Webkit is also Safari.
|
47
|
+
if ( NoReferrer.Browser.browser.chrome ) {
|
48
|
+
NoReferrer.Browser.browser.webkit = true;
|
49
|
+
} else if ( NoReferrer.Browser.browser.webkit ) {
|
50
|
+
NoReferrer.Browser.browser.safari = true;
|
51
|
+
}
|
52
|
+
},
|
53
|
+
uaMatch: function(ua){
|
54
|
+
ua = ua.toLowerCase();
|
55
|
+
|
56
|
+
var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
|
57
|
+
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
|
58
|
+
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
|
59
|
+
/(msie) ([\w.]+)/.exec( ua ) ||
|
60
|
+
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
|
61
|
+
[];
|
62
|
+
|
63
|
+
return {
|
64
|
+
browser: match[ 1 ] || "",
|
65
|
+
version: match[ 2 ] || "0"
|
66
|
+
};
|
67
|
+
}
|
68
|
+
},
|
69
|
+
Link: {
|
70
|
+
go: function(url){
|
71
|
+
if(NoReferrer.Browser.browser['msie']){
|
72
|
+
if(new RegExp(/\?/).test(url)){
|
73
|
+
window.open(url + '&_='+Math.random());
|
74
|
+
}
|
75
|
+
else{
|
76
|
+
window.open(url + '?_='+Math.random());
|
77
|
+
}
|
78
|
+
}
|
79
|
+
else if(NoReferrer.Browser.browser['webkit']){
|
80
|
+
if(new RegExp(/\?/).test(url)){
|
81
|
+
location = "data:text/html,<script>location='" + url + '&_=' + Math.random() + "'</scr"+"ipt>";
|
82
|
+
}
|
83
|
+
else{
|
84
|
+
location = "data:text/html,<script>location='" + url + '?_=' + Math.random() + "'</scr"+"ipt>";
|
85
|
+
}
|
86
|
+
return false;
|
87
|
+
}
|
88
|
+
else if(NoReferrer.Browser.browser['mozilla']){
|
89
|
+
location = 'data:text/html,<html><meta http-equiv="refresh" content="0; url='+ url + '"></html>';
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
};
|
94
|
+
|
95
|
+
$.fn.noreferrer = function(matches) {
|
96
|
+
NoReferrer.Browser.init();
|
97
|
+
if(matches != undefined){
|
98
|
+
for(i=0;i<matches.length;i++){
|
99
|
+
matches[i]
|
100
|
+
}
|
101
|
+
}
|
102
|
+
this.on('click', function(e){
|
103
|
+
if(matches == undefined){
|
104
|
+
NoReferrer.Link.go($(this).attr('href'));
|
105
|
+
return false;
|
106
|
+
}
|
107
|
+
else{
|
108
|
+
for(i=0;i<matches.length;i++){
|
109
|
+
if(new RegExp(matches[i]).test($(this).attr('href'))){
|
110
|
+
NoReferrer.Link.go($(this).attr('href'));
|
111
|
+
return false;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
});
|
116
|
+
return this;
|
117
|
+
};
|
118
|
+
})(jQuery);
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: noreferrer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rodney Carvalho
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-28 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Removes referrer information on an html link.
|
15
|
+
email:
|
16
|
+
- rcarvalho@atlantistech.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- README.md
|
22
|
+
- lib/noreferrer.rb
|
23
|
+
- noreferrer.gemspec
|
24
|
+
- vendor/assets/javascripts/noreferrer.js
|
25
|
+
homepage: https://github.com/rjcarvalho/noreferrer
|
26
|
+
licenses: []
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
none: false
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 1.8.23
|
46
|
+
signing_key:
|
47
|
+
specification_version: 3
|
48
|
+
summary: Removes referrer information on an html link.
|
49
|
+
test_files: []
|