Browse Source

change default referrer policy to support old browsers

master
hole-thu 3 years ago
parent
commit
dd1ecd724d
  1. 3
      public/index.html
  2. 38
      src/Common.js

3
public/index.html

@ -5,9 +5,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="icon" href="%PUBLIC_URL%/static/favicon/512.png"> <link rel="icon" href="%PUBLIC_URL%/static/favicon/512.png">
<meta name="format-detection" content="telephone=no"> <meta name="format-detection" content="telephone=no">
<meta name="referrer" content="same-origin">
<meta name="mobile-web-app-capable" content="yes"> <meta name="mobile-web-app-capable" content="yes">
<link rel="shortcut icon" href="%PUBLIC_URL%/static/favicon/512.png"> <link rel="shortcut icon" href="%PUBLIC_URL%/static/favicon/512.png">
<link rel="manifest" href="%PUBLIC_URL%/manifest.json"> <link rel="manifest" href="%PUBLIC_URL%/manifest.json">

38
src/Common.js

@ -140,14 +140,16 @@ export class HighlightedMarkdown extends Component {
{ {
shouldProcessNode: (node) => node.name === 'img', shouldProcessNode: (node) => node.name === 'img',
processNode(node, index) { processNode(node, index) {
const rp = const with_referrer =
STORAGE_BASE && node.attribs.src.startsWith(STORAGE_BASE) STORAGE_BASE &&
? 'origin' node.attribs.src &&
: 'no-referrer'; node.attribs.src.startsWith(STORAGE_BASE);
const rp = with_referrer ? 'origin' : 'no-referrer';
return ( return (
<a <a
href={normalize_url(node.attribs.src)} href={normalize_url(node.attribs.src)}
target="_blank" target="_blank"
rel={with_referrer ? 'noopener' : 'noopener noreferrer'}
referrerPolicy={rp} referrerPolicy={rp}
> >
<span className="ext-img__warpper loading"> <span className="ext-img__warpper loading">
@ -167,16 +169,16 @@ export class HighlightedMarkdown extends Component {
{ {
shouldProcessNode: (node) => node.name === 'a', shouldProcessNode: (node) => node.name === 'a',
processNode(node, children, index) { processNode(node, children, index) {
const with_referrer =
STORAGE_BASE &&
node.attribs.href &&
node.attribs.href.startsWith(STORAGE_BASE);
return ( return (
<a <a
href={normalize_url(node.attribs.href)} href={normalize_url(node.attribs.href)}
target="_blank" target="_blank"
rel="noopenner" rel={with_referrer ? 'noopener' : 'noopener noreferrer'}
referrerPolicy={ referrerPolicy={with_referrer ? 'origin' : 'no-referrer'}
STORAGE_BASE && node.attribs.href.startsWith(STORAGE_BASE)
? 'origin'
: 'no-referrer'
}
className="ext-link" className="ext-link"
key={index} key={index}
> >
@ -218,11 +220,13 @@ export class HighlightedMarkdown extends Component {
return ( return (
<React.Fragment key={index}> <React.Fragment key={index}>
{splitted.map(([rule, p], idx) => { {splitted.map(([rule, p], idx) => {
const with_referrer =
STORAGE_BASE && p && p.startsWith(STORAGE_BASE);
return ( return (
<span key={idx}> <span key={idx}>
{rule === 'url_pid' ? ( {rule === 'url_pid' ? (
<span <span
className="url-pid-link" className="url-pid-link clickable"
title={p} title={p}
onClick={(e) => { onClick={(e) => {
e.preventDefault(); e.preventDefault();
@ -237,21 +241,17 @@ export class HighlightedMarkdown extends Component {
href={normalize_url(p)} href={normalize_url(p)}
className="ext-link" className="ext-link"
target="_blank" target="_blank"
rel="noopener" rel={
with_referrer ? 'noopener' : 'noopener noreferrer'
}
referrerPolicy={ referrerPolicy={
STORAGE_BASE && p.startsWith(STORAGE_BASE) with_referrer ? 'origin' : 'no-referrer'
? 'origin'
: 'no-referrer'
} }
> >
{p} {p}
<span className="icon icon-new-tab" /> <span className="icon icon-new-tab" />
</a> </a>
{/*
这里对referrer暂时没有比较好的办法
如果使用ifrmae对fireofx可行在chomre上很容易变成下载
*/}
{is_video(p) && ( {is_video(p) && (
<video className="ext-video" src={p} controls /> <video className="ext-video" src={p} controls />
)} )}

Loading…
Cancel
Save