Chrome扩展程序在YouTube页面上注入HTML

时间:2018-05-13 21:34:28

标签: javascript ajax dom google-chrome-extension youtube

我正在创建一个Chrome扩展程序,它会在YouTube视频的相关视频栏上方插入HTML。

This is the desired effect of the plugin.

以下是<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="MVVMFramework.VVMs.Main.MainPage" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:MVVMFramework" xmlns:nav="clr-namespace:MVVMFramework.Navigation.NavigationHeader" xmlns:vm="clr-namespace:MVVMFramework.VVMs.Main"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="20" /> <RowDefinition Height="200" /> </Grid.RowDefinitions> <ContentView Grid.Row="0" Content="{Binding NavHeader}" HorizontalOptions="Start" VerticalOptions="Start" BindingContext="{Binding Source = {nav:NavigationHeaderViewModel}}"/> <ContentView Grid.Row="1" Content="{Binding DisplayedView}" HorizontalOptions="Center" VerticalOptions="Center" BindingContext="{Binding Source = {vm:MainPageViewModel}}"/> </Grid> </ContentPage>

manifest.json

这是{ // Required "manifest_version": 2, // App "name": "...", "version": "...", "author": "...", "description": "...", "content_scripts": [ { "run_at": "document_idle", "matches": ["*://www.youtube.com/watch?v=*"], "js": ["jquery-min-3.3.1.js", "inject.js"] } ] }

inject.js

当扩展程序加载到Chrome并加载了YouTube视频页面时,该脚本似乎可以工作一秒钟。 $(document).ready(function(){ $('#related').prepend('<h1>This was injected throught jQuery.</h1>'); }); 栏顶部注入h1,直到相关视频缩略图开始加载。然后,当每个新缩略图加载时,快速注入的#related被推到底部。

我猜这与YouTube使用AJAX加载内容有关。有没有办法在注入HTML之前等待所有AJAX加载?

0 个答案:

没有答案